/home/bill/System maintenence/windows management wmctrl.txt #************************** # 12Aug2013 So maybe the command wmctrl is key? http://movingtofreedom.org/2010/08/10/arranging-windows-from-the-gnulinux-command-line-with-wmctrl/ "arranging windows from the gnu/linux command line with wmctrl" The wmctrl home page has useful information, and the man page is helpful, but I thought I’d throw a few examples and comments from my own experience out here, as always with the hope that I might contribute in some small way to the greater free software good. You can get information about your virtual desktops (workspaces) with wmctrl -d: 0 - DG: 2944x1280 VP: N/A WA: 0,25 2944x1004 [First] 1 * DG: 2944x1280 VP: 0,0 WA: 0,25 2944x1004 [Second] 2 - DG: 2944x1280 VP: N/A WA: 0,25 2944x1004 [Third] And list open windows with wmctrl -l. The -G option shows you the geometry of the windows: 0x042000af 0 1988 71 956 978 bigbird Unsaved Document 2 - gedit 0x03e00a84 1 0 46 1024 1256 bigbird Moving to Freedom - Mozilla Firefox 0x018225e4 1 1031 71 956 469 bigbird scarpent@bigbird: ~ Switch to a different virtual desktop with the -s option. For example, go to the first desktop with: wmctrl -s 0. I had some odd behavior at first when I used other methods of moving windows to different desktops. I’m not sure what that was all about, but using -s before starting and rearranging windows worked much better for me. *** Note, 29 August 2010: I recently discovered after upgrading to Ubuntu 10.04 (“Lucid Lynx”) that if visual effects are enabled (in System » Preferences » Appearance), multiple desktops/workspaces will appear to wmctrl as one big area, like so: 0 * DG: 8832x1280 VP: 0,0 WA: 0,24 2944x1256 [First] And the -s action will have no effect or will cause an error if something other than 0 is given. wmctrl will still work for launching windows, but it seems you have to already be in the desired workspace when running it. *** You can specify a window by referencing its title or partial title after -r. -e is for moving and resizing: wmctrl -r "Mozilla Firefox" -e ,,,, From the wmctrl documentation: : Gravity specified as a number. The numbers are defined in the EWMH specification. The value of zero is particularly useful, it means "use the default gravity of the window". ,: Coordinates of new position of the window. ,: New width and height of the window. So, to move a window to the upper left corner and make it 1000 pixels wide by 700 tall, you’d use 0,0,0,1000,700. What if there is more than one window with the same title? For example, “Mozilla Firefox.” For that, I turned to the -l window list command. It seems that the list is in order with newly opened windows appearing at the bottom. I wrote a bash function to find the most recent one so that I could extract the unique numeric window ID: function get_window_id() { window_id=$(wmctrl -l | grep "$1" | tail -1 | cut -f1 -d" ") } And then you can use the -i option to tell it to interpret the -r argument as a numeric window ID, like so: get_window_id "Mozilla Firefox" wmctrl -i -r "$window_id" -e 0,1025,0,953,100 In your script, you control when windows are created, so you can make assumptions about the most recent instance being the one you want to position. On another Firefox note, I saw where people have struggled with it because Firefox will remember its window state from when it last closed. If it was maximized, it will start maximized, which can cause problems when you try to move/resize it. For that, I used the workaround of “unmaximizing” it first, using the -b option. -b can be used to change the state of a window. There are many window state properties defined by the EWMH spec, not all of which made sense to me, or for which I could find good explanations. But I eventually figured out that you can restore a window to a non-maximized state with this command: wmctrl -r "Mozilla Firefox" -b remove,maximized_vert,maximized_horz If it’s already not maximized, then that seems to be fine. It has no effect. Then you can move/resize the window, and then maximize it again if you so desire, with: wmctrl -r "Mozilla Firefox" -b add,maximized_vert,maximized_horz In addition to the add and remove actions, there is also toggle. Note that sometimes you “don’t need no stinkin’ helper programs.” For Gnome Terminal I used the built-in --geometry x++ option. In this case, width and height are given in terminal characters instead of pixels. To position a window on the upper left corner of my right monitor, I used gnome-terminal --geometry 117x26+1025+0. sleep statements are helpful to make sure things have time to start or be ready for “unmaximization.” Don’t fret over the delay. If it takes a few more seconds, that’s just more time to bask in the glory of your new automated process. Example: gedit --new-window & sleep 1 get_window_id gedit wmctrl -i -r "$window_id" -e 0,1025,0,953,1000 Don’t forget to use ampersands where necessary to background the process. With gedit, for example, I’m used to launching new windows in an existing process where it’s not necessary to background each one. But if you’re running a script and you launch the first instance, your script will halt if you don’t background it.