Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On windows I have a few AutoHotkey scripts that let me hit various key combinations to resize windows to particular pre-defined sizes, or move them to certain areas of the screen (or both). I'm wondering how I would accomplish this in Ubuntu (gnome).

Most of the searches I did for a linux version of autohotkey seemed to be centered around just setting up simple keyboard shortcuts (key combo X launches app Y, etc). I didn't see anything about scripting window size and placement beyond maximize/minimize.

share|improve this question
Won't add it as an answer cos it's too vague I'm afraid - I use to have Compiz installed and I used it to open up a terminal window at a preset size when I pressed a shortcut key. I know this isn't exactly what you want, but try looking under Compiz - there might be something there. – Andy Jun 16 '10 at 13:34
Opening a window at a particular size is rather easy. The trick is being able to modify pre-existing windows. – Herms Jun 16 '10 at 13:54
Minimize and Maximize are usually built into your window mananger, not sure about move windows -- I had a similar question for Xubuntu ( – wag2639 Jun 16 '10 at 17:13
min and max aren't what I want. I'm looking for something where I can set specific sizes. For instance, one thing I had in windows was to set the size to 90% of the current screen. – Herms Jun 16 '10 at 18:06
I know that opening at a particular size is easy, and I know it's not what you're after... it's just my vague recollection of setting up my terminal make me think there might be something useful for you there. If I still used it I'd check it out for you! – Andy Jun 17 '10 at 9:16
up vote 2 down vote accepted

In shell scripts you can use wmctrl (not installed by default in Ubuntu, but you can install it using the package manager) to move and resize windows.

The following script resizes the current window to 90% of the screen width and height:


set -- $(xwininfo -root| awk -F '[ :]+' '/ (Width|Height):/ { print $3 }')

wmctrl -r :ACTIVE: -e 0,-1,-1,$((width*90/100)),$((height*90/100))

This should work in Xubuntu, too.

share|improve this answer
Looks like that gives the total width/height of the entire logical screen, not just a single monitor. Any way to get the size screen area that's specific just to one of the monitors? – Herms Jun 16 '10 at 18:38
And if you have a chance and wouldn't mind, could you give a brief explanation of what each part of that is for (mainly the args to awk)? Will make it easier to customize that. – Herms Jun 16 '10 at 18:42
+1 for answer, +1 to request for explanation ;) – Andy Jun 17 '10 at 9:22
"xwininfo -root" prints some information about the root window. awk takes its output, selects the lines containing either " Width:" or " Height:" and prints the values. Usally "awk '/ (Width|Height):/ { print $2 }'" works here, too, I just needed the longer one to work around a bug some time ago and got used to it. The two values are then used as arguments to "set --" which sets $1 and $2 to that values. For better readability I want to use $width and $height instead so I set them accordingly. In the wmctrl call this variables are then used to calculate the new window width and height. – Florian Diesch Jun 17 '10 at 13:52
I don't know how to get the size of the monitor a window is on if your screen is stretched on multiple monitors and I don't have a second monitor around to try a bit. Maybe one could use xrandr to get the resolutions and then use the screen position to find out which monitor it is. Getting this right with all the options for turning, reflecting, scaling, ... and all possible relative monitor positions may get a bit tricky. Maybe it's worth a question of its own... – Florian Diesch Jun 17 '10 at 14:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .