Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

When undocking my laptop from twinview external monitors back to a single screen I would like to have a single command to move all windows onto my primary screen.

Although nvidia does some of the work so that I can see the edge of the windows, moving each one with the mouse, keyboard or compiz plugins takes time.

share|improve this question

You can use wmctrl and a little bash script to loop through the windows and then position them onto your primary display. I threw this together. It might be sufficient for you.

#! /bin/bash

#dump the list of windows to a file
wmctrl -l > /tmp/window_list.txt
x=40; y=40

#read the window information from the file
while read id sticky host win_title; do

    #move any non-sticky windows except the desktop
    if [ "$sticky" == "0" -a "$win_title" != "x-nautilus-desktop" ]
        wmctrl -i -r $id -e 0,$x,$y,-1,-1
        x=$(($x + 40))
        y=$(($y + 40))

done < /tmp/window_list.txt

#delete the temporary file
rm /tmp/window_list.txt
exit 0

Save it to a file called "" or something and give it execute permissions with chmod +x and then create a launcher for it.

share|improve this answer
Oh, almost forgot. I don't use Unity so I'm not sure what it will do in that environment. – Ramón May 26 '11 at 0:26
Yep it need some tweaks for unity, ill test again tomorrow. – Cas May 26 '11 at 1:38
Thank you! Your script was very useful in finding a workaround for a bug I had with openbox (it would crash every time I switched monitor configuration if a window was on an external monitor). – Glutanimate Mar 7 '13 at 4:14

I would love to find a better solution, but Compiz has Grouping of windows.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.