Whenever I use my MacBook away from my desk and later plug it into an external display (as primary), I get into the state of having windows deposited in both the notebook monitor and the external one.

To move all windows to a single screen, my current solution is to "Turn on mirroring" in the display preferences and then turn it off again. This is rather tedious, though. Does anyone know of a better way?


I'm afraid the script posted by @erlando does absolutely nothing for me, running Mac OS X 10.5.4. (I.e., with windows on both screens, running the script moves not a single one of them, and it does not return any errors.) I guess I'll just have to stick with using the "mirror/unmirror" method mentioned above.


@Denton: I'm afraid those links provide scripts for getting windows which are orphaned from any screen back onto the display. I ‘just’ want to move all windows from a secondary display onto the primary display.

6

Best Answer


Cmd+F1 appears to be a Mirror Displays shortcut in Snow Leopard. Don't know about Lion, etc, though.

Just tap it twice and see what happens (-:

For the people who prefer to set up their function keys to act in the old-fashioned way (not as brightness/sound controls etc.), it will be Cmd+Fn+F1

On Lion you can toggle Mirror Displays using fn+Cmd+F1 (provided you are using the media control keys as default).

This also works on Snow Leopard and likely everything in between, also possibly further back.

You can click the "Gather Windows" button in the Displays preference pane.

Here is a command-line script to do just that: http://zach.in.tu-clausthal.de/software/.

It's a little down the page under "Move Off-Screen Windows to the Main Screen".


-- 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.

screenshot

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.