If you're like me and have a monitor/TV hooked up that's either powered off or in the other room or hidden in the torture chamber in the wine cellar, you have a problem with stray windows getting stuck on other monitors.
I found a script on another website which works pretty well but throws an error every time that was annoying me. Not only that, but it's not application-specific.
I prefer to use a free application like Fast Scripts in conjunction with my modified version of the script. This allows me to just get the windows I want from the frontmost app with a hotkey which I defined myself (I chose CTRL+M). The "newpos" variable might need to be modified if you have a tiny screen resolution and like 40 windows, but other than that, everything seems to work well.
Here's the modified script:
Code:
tell application "Finder"
set _b to bounds of window of desktop
set screen_width to item 3 of _b
set screen_height to item 4 of _b
end tell
tell application "System Events"
set frontmostapp to item 1 of (get name of processes whose frontmost is true)
tell process frontmostapp
repeat with x from 1 to (count windows)
set winPos to position of window x
set _x to item 1 of winPos
set _y to item 2 of winPos
set newpos to (x - 1) * 32
if (_x < 0 or _y < 0 or _x > screen_width or _y > screen_height) then
set position of window x to {newpos, (newpos + 22)}
end if
end repeat
end tell
end tell