Gnome shell: automating windows and placement

uz flag

First off, sorry if this isn't the best formed question. I've tried to research the best part of the stack to focus on, but I'm still not 100% sure I've got it.

So, I'll explain the outcome I'm after:

On Ubuntu 20.04 (GNOME Shell 3.36.9 / Xorg) I have a window configuration I set up every morning (for our company stand up): one Firefox window snapped to the right column with a URL open, and one snapped to the left column with another URL.

I understand how to open a URL in a browser, but the thing I want to automate is a little different:

  1. Open a new browser window in a new workspace (ideally at the top of the workspaces)
  2. Snap that window to the right
  3. Open another new browser window in the same workspace, snapped left
  4. Have both browser windows open the URLs I'm after
  5. Bonus points for opening them in the Firefox containers I use, but I appreciate that's a Firefox issue, not a Gnome one.

Ideally this would be something I can script using bash or python.

My question is: is this sort of thing even possible? What APIs or tooling should I be looking at, or are there projects that do this sort of thing already? It seems like a useful thing to have, as everyone must have a set of common window setups they want to save.

My lack of understanding of the Gnome ecosystem is making this hard to search for.

24601 avatar
in flag
may not do all you ask but have you looked at the GNOME extension Put Windows in association with `Startup Applications`?
cn flag

You can manipulate windows using wmctrl and xdotool, and in addition, daemons such as devilspie and devilspie2 allow you to define rules for specific windows. When a window is created that matches your criteria, these tools can automatically manipulate them, i.e. resize and position them, and move them to a different workspace. You will mist likely need to be logged in on the Xorg server (default prior to Ubuntu 21.04). They may not work, or at least be limited, under Wayland.

wmctrl and xdotool

If you only need to set up a configuration at login, you can work with wmctrl and xdotool. With wmctrl, you can move to a different workspace, then have your script launch an application. xdotool may then be most suited to "search" the window and resize and place it. It features a --sync option that causes the command to wait until the window is effectively created.

devilspie or devilspie2

devilspie2 is a successor of devilspie that uses a different syntax (Lua) in the configuration file. With these tools, you define rules in which you state what should happen with a window that matches certain criteria. As soon as such window is created, devilspie will manipulate it according to the instructions, i.e., resize and position it, move it to a different workspace, ...

Thus, you could define rules for the specific Firefox windows you want to place during startup. When the windows are created by an autostarter or by a script you run on startup, devilspie will manipulate them automatically as they are created.


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.