I'm wondering is there any way to achieve the affect of the Ctrl-Alt-Keypad shortcuts in Unity using terminal commands instead? I want a command that sets a gui window to half the size of the screen, either left or right aligned.
By way of background, I'm writing a script that runs after log in. It uses Zenity to ask whether or not I want to open my development environment (GVim and IPython side-by-side). I have been trying to achieve two equal-sized windows for these programmes by using set lines= columns=
in my .gvimrc
and c.IPythonWidget.width =
and c.IPythonWidget.height =
in my ipython_qtconsole_config.py
. However, there are problems associated with this approach.
Best Answer
What you will run into
If you want to first call an application and, subsequently, place its window on a specific position and size, the time between calling the application and the moment the window actually appears, is unpredictable. If your system is occupied, it can be significantly longer than if it is idle.
You need a "smart" way to make sure the positioning/resizing is done (immediately) after the window appears.
Script to call an application, wait for it to appear and position it on the screen
With the script below, you can call an application and set the position and size it should appear on with the command:
An few examples:
To call
gnome-terminal
and resize its window to 50% and place it on the right half:To call
gedit
, place its window on the left and callgnome-terminal
, place it on the right (setting itsv-size
46% to give it a little space between the windows):To call Inkscape, place its window in the left/upper quarter of the screen:
The script and how to use it
install both
xdotool
andwmctrl
. I used both since resizing withwmctrl
can cause some peculiarities on (specifically)Unity
.setwindow
(no extension) in~/bin
; create the directory if necessary.~bin
, run:source ~/.profile
Test-run the script with the command (e.g.)
In other words:
If all works fine, use the command wherever you need it.
The script
What it does
When the script is called, it:
wmctrl -lp
)ps -ef ww
, comparing the pid of the window to the pid of the application)Minor issue
In Unity, when you (re-)position and (re-)size a window with either
wmctrl
orxdotool
, the window will always keep a small marge to the borders of your screen, unless you set it to 100%. You can see that in the image (3) above; while theinkscape
window was placed onx
position 0, you can still see a minor marge between the Unity Launcher and theinkscape
window.