0

This question shows how one can address a window by it's title, and then position/resize it around.

Now to address a window there are five options:
- The window's ID: Changes on application restart => Useless
- The window's Title: Identical with the title of other windows => Useless
- The window's Namespace: Identical with the namespace of other windows => Useless
- User selectable via clicking => The whole point of this is to be lazy, isn't it?
- The active window will be used => Maybe, but I feel like this could be unreliable (?)

What I want to do is to have a script open a bunch of applications, a few of them more than once (same or variable title) and position them on my desktops. Note the plural, I want some of them to go on another workspace aswell. wmctrl is capable of doing all that moving and resizing, but I'm not sure how to do the window selection.

Is there a way to get the Window ID right after starting the app? I know you can do this for the process ID, and wmctrl is able to get the PID for all apps I'm running, so is there a way to address a window using it's PID?

Alternatively, can wmctrl do the title matching in reverse? (The --help says the first match will be used, is it possible to use the most recently started (so I assume last) match instead?)

0

Thought of this solution when the question was already almost done, so figured I'd self-answer. This works reliably, but there might be an easier way. If there's a way to do what I asked directly feel free to leave another answer.

How to move and resize any application via script:

This example code should be self-explanatory (with its comments):

#!/bin/bash
DISPLAY=:0 gnome-calculator & # start app
cpid=$! # get process ID of said app
sleep 1 # give it a second to open the window (adjust to needs)
cwid=$(wmctrl -lp | grep " $cpid " | cut -d " " -f 1) # get window ID
wmctrl -i -r "$cwid" -e "0,3200,572,396,415" # move and resize!
# start the 2nd application...
DISPLAY=:0 sol &
cpid=$!
sleep 1
cwid=$(wmctrl -lp | grep " $cpid " | cut -d " " -f 1)
wmctrl -i -r "$cwid" -b "remove,maximized_vert,maximized_horz" # un-maximize
wmctrl -i -r "$cwid" -t 1 # move to desktop 1 (2nd workspace)
wmctrl -i -r "$cwid" -e "0,1497,525,1342,860"

Just repeat for as many applications as you need, you can use wmctrl -l to find out the current geometry of the applications so you know what you wanna supply to the -e argument.

The format of the -e argument is: <gravity>,<X_pos>,<Y_pos>,<width>,<height>.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.