If you run the script below with the arguments:
<application> <x> <y>
The window of the application will be placed at x, y on your screen.
How to set up
The script uses both wmctrl
and xdotool
:
sudo apt-get install wmctrl
sudo apt-get install xdotool
Then:
- The most elegant way is to Copy the script into an empty file and save it in
~/bin
(you might have to create the directory) as place_window
(no extension)
- Make the script executable (!)
If you just created ~/bin
, either log out / in or run the command:
source ~/.profile
Test run it with the command (e.g):
place_window gedit 100 100
A gedit window should appear at x = 100, y = 100 on your screen.
If all works fine, you can either put the command under a shortcut combination (choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts"), or at it as a quicklist -shortcut to an application launcher.
The script:
#!/usr/bin/env python3
import subprocess
import getpass
import time
import sys
app = sys.argv[1]
user = getpass.getuser()
get = lambda x: subprocess.check_output(["/bin/bash", "-c", x]).decode("utf-8")
ws1 = get("wmctrl -lp"); t = 0
subprocess.Popen(["/bin/bash", "-c", app])
while t < 30:
ws2 = [w.split()[0:3] for w in get("wmctrl -lp").splitlines() if not w in ws1]
procs = [[(p, w[0]) for p in get("ps -u "+user).splitlines() \
if app[:14] in p and w[2] in p] for w in ws2]
if len(procs) > 0:
w_id = procs[0][0][1]
cmd1 = "wmctrl -ir "+w_id+" -b remove,maximized_vert remove,maximized_horz"
cmd2 = "xdotool windowmove "+w_id+" "+sys.argv[2]+" "+sys.argv[3]
for cmd in [cmd1, cmd2]:
subprocess.call(["/bin/bash", "-c", cmd])
break
time.sleep(0.5)
t = t+1
How it works
The scripts runs the command to start the application, waits for the corresponding window to appear (waiting for the pid to produce a new window) and positions it to the coordinates you define.
place_window gedit 50 150

place_window gedit 150 50

Setting the command as a quicklist item
The most elegant would be to add it as a keyboard shortcut, or, alternatively, as a quicklist item:

In that case, the command to use in the Exec=
line would be e.g.:
Exec=/bin/bash -c "place_window gedit 600 600"
place_window gedit 100 100
I getbash: /home/admin/bin/place_window: Permission denied
orplace_window: command not found
– JoKeR Apr 12 '15 at 22:44~/bin
.admin
is your username right? In any case it should work with:python3 /path/to/place_window gedit 100 100
– Jacob Vlijm Apr 13 '15 at 05:34./
before name of the script to launch it in folder. – andrybak Apr 13 '15 at 07:59Exec=/bin/bash -c "place_window gedit 600 600"
because I'm a bit lost or doing smth wrong, I want to add it as a quicklist item. – JoKeR Apr 13 '15 at 09:21smplayer.desktop
to make it work. Thanks for helping. – JoKeR Apr 13 '15 at 10:35