-- Source: http://www.jonathanlaliberte.com/2007/10/19/move-all-windows-to-your-main-screen/-- and: http://www.macosxhints.com/article.php?story=2007102012424539---- Improvements:-- + code is more efficient and more elegant now-- + windows are moved also, if they are "almost" completely off-screen -- (in the orig. version, they would be moved only if they were completely off-screen)-- + windows are moved (if they are moved) to their closest position on-screen-- (in the orig. version, they would be moved to a "home position" (0,22) )-- Gabriel Zachmann, Jan 2008-- Example list of processes to ignore: {"xGestures"} or {"xGestures", "OtherApp", ...}property processesToIgnore : {"Typinator"}-- Get the size of the Display(s), only useful if there is one display-- otherwise it will grab the total size of both displaystell application "Finder"set _b to bounds of window of desktopset screen_width to item 3 of _bset screen_height to item 4 of _bend telltell application "System Events"set allProcesses to application processesrepeat with i from 1 to count allProcesses--display dialog (name of (process i)) as stringif not (processesToIgnore contains ((name of (process i)) as string)) thentrytell process irepeat with x from 1 to (count windows)set winPos to position of window xset _x to item 1 of winPosset _y to item 2 of winPosset winSize to size of window xset _w to item 1 of winSizeset _h to item 2 of winSize--display dialog (name as string) & " - width: " & (_w as string) & " height: " & (_h as string)if (_x + _w < 40 or _y + _h < 50 or _x > screen_width - 40 or _y > screen_height - 40) thenif (_x + _w < 40) then set _x to 0if (_y + _h < 50) then set _y to 22if (_x > screen_width - 40) thenset _x to screen_width - _wif (_x < 0) then set _x to 0end ifif (_y > screen_height - 40) thenset _y to screen_height - _hif (_y < 22) then set _y to 22end ifset position of window x to {_x, _y}end ifend repeatend tellend tryend ifend repeatend tell
As you said, the best answer seems to be turning "Mirror Displays" on and off again. Afterwards, all windows will have been collected on the main screen, and the secondary screen will be empty.
This is a bit cumbersome, but nothing else has worked for me in Lion.
There is an article on using AppleScript to do this at macosxtips.co.uk, and another at macosxhints.com.