This is similar to Quickly place a window to another screen using only the keyboard , but I want to be able to use the command line (so that all I need to do is to recall the command line from the bash history).
E.g., send
- all the gnome terminal windows to
eDP1
, - all Emacs windows to
VGA1
, and - all Chrome windows to
HDMI1
(and maximize them after moving - but not the crazy F11 way, the normal window-manager-style maximization).
I would like to specify windows by the executable name.
Moving all windows of a specific window class to a specific screen by (screen-) name
The script below will send windows, belonging to a specific
WM_CLASS
(application), to a specific screen, by the screen's name. How that is done is explained in the script and also further below.The script assumes the screens are arranged horizontally, and more or less top- aligned (with a difference < 100 PX).
The script
How to use
The script needs both
wmctrl
andxdotool
:Copy the script below into an empty file, save it as
move_wclass.py
Run it by the command:
for example:
For the
WM_CLASS
, you may use part of theWM_CLASS
, like in the example. The screen's name needs to be the exact and complete name.How it is done (the concept)
The explanation is mostly on the concept, not so much on the coding.
In the output of xrandr, for every connected screen, there is a string/line, looking like:
This line gives us information on the screen's position and its name, as explained here.
The script lists the information for all screens. When the script is run with the screen and the window class as arguments, it looks up the (x-) position of the screen, looks up all windows (-id's) of a certain class (with the help of
wmctrl -l
and the output ofxprop -id <window_id>
.Subsequently, the script moves all windows, one by one, to a position on the targeted screen (using
wmctrl -ir <window_id> -e 0,<x>,<y>,<width>,<height>
) and maximizes it (withxdotool windowsize 100% 100%
).Note
The script worked fine on the tests I ran it with. Using
wmctrl
, and evenxdotool
, on Unity can have some stubborn peculiarities however that sometimes need to be solved by experiment rather than reasoning. If you might run into exceptions, please mention.I've rewrited @jacobs python code to simple bash and make it works (I tested this on ubuntu 16 cinnamon).
I had to add
remove,maximized_vert, remove,maximized_horz
without that windows didn't move.sudo apt-get install xdotool wmctrl
/path/to/script.sh "window-name" "monitor-name"
For the record, here is what I use for the combination of this question and Restore multiple monitor settings:
you would need to use wmctrl version 0.3 or later (because of my pull request).
Based on @AndrzejPiszczek's answer, here's a way to move all windows to a specific screen: