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.