Score:0

How do I move/maximize/activate desktop windows using `dbus` in terminal?

bs flag

Problem

I'm on a default Ubuntu 22.04 desktop. I repeatedly have to move windows around on my desktop and I would like to do that using a script.

wmctrl

This seems like it was a solution in the past and it still works with some apps (e.g.: Signal desktop), but for example it does not recognize the terminal window (anymore?).

dbus

I've read a couple of threads where people used dbus to do some automation. And it makes sense to me that this could be the solution. I just have trouble finding the information or even finding out if this is at all possible.

Using d-feet I see a bunch of stuff in the system and session bus. And I even managed to get some info (org.gnome.Terminal has a bunch of methods). But now I'm already at my first blocker: What kind of parameter do they expect?

/org/gnome/Terminal/window/1

Activate (String action_name, Array of [Variant] parameter, Dict of {String, Variant} platform_data) ↦ ()

If I want to activate a window, what else could it expect other than the window ID?

Other apps

Signal offers some methods but they're all about notifications. Thunderbird and pycharm do not offer anything.

Summary

I think if I want to manage windows (move, maximize, minimize, activate), I should be talking to a desktop service? Not the apps themselves? How do I find more info on what to do? Is there documentation on what parameters those methods expect? I'm totally fine if you only have pointers to additional documentation since this seems kind of a new area and people don't have that one super command at hand that solves all issues.

Score:0
cn flag

To manipulate windows in Gnome Shell from the command line, you can install the extension Window Calls by domandoman. It exposes a dbus interface that can return list of windows, move, resize, close them etc. The extension Window Calls Extended by hseliger expands on this in that it allows to obtain information on the window under focus.

hofrob avatar
bs flag
Ok, thanks. The problem with this library/extension is the first command in the README already doesn't work: `Error: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: Object does not exist at path “/org/gnome/Shell/Extensions/Windows”`. I tried to find similar methods by using `busctl tree --user org.gnome.Shell.Extensions`, but haven't found anything yet.
vanadium avatar
cn flag
I played with this extension before and had no issues. Sure the extension is properly installed? Perhaps try logging out and in again.
hofrob avatar
bs flag
Oh, I get it now. I thought those commands should work even without the extension. I will try to use this as an example to figure this out. Thanks!
vanadium avatar
cn flag
These extensions expose custom dbus interfaces, so yes, they must be installed. In recent gnome shell versions, the standard gnome shell dbus interfaces are not anymore accessible from the terminal.
hofrob avatar
bs flag
Thanks a lot! It works now (after fixing issues with how gnome extensions are run/installed). I can write scripts to handle all my windows exactly as I need it.
vanadium avatar
cn flag
If his answer helped you, then please "accept" it: click the check-mark next to the question. This shows appreciation and also hints other users that a useful answer can be found here.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.