Cheapskate way to move all windows to main display with applescript
Alec Jacobson
November 02, 2010
There seems to be a lot of OS X version specific scripts that "move all windows onto main display". None of which immediately worked for my machine.
What I did notice is that if you twiddle the "mirror displays option" all the windows get lumped together on the one mirrored display and then when set back to dual screens the windows are all pushed to the main display, (not back to where they were before). Feature? Bug? Right now I don't care. I'm just going to take advantage of it as an easy way to gather my windows. Here's the script:
repeat 2 times
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.displays"
end tell
tell application "System Events" to tell window 1 of process "System Preferences"
try
tell tab group 1 to click radio button "Arrangement"
on error
return "Only one display available."
end try
tell group 1 of tab group 1
click checkbox "Mirror Displays"
end tell
end tell
end repeat
Note: Downside is that it's kind of slow. So it's only worth while if you have quite a few windows over there.
Update: Turns out this only works if your main display is your second display. Instead try my new solution.