I recently had a problem with my iMac. I accidentally dragged a window right off the screen and left it hanging out there…and I couldn’t get it back for the life of me. You’re here because you probably did the same thing.
I did some searching…
Do this:
1: Click on the little Apple icon at the top left of your screen
2: Click “System Preferences”
3: Click “Universal Access” (icon is a stickman in a blue circle)
4: Click “Enable Access for Assistive Devices” (at the bottom)
5: Exit System Preferences
6: Open “Finder”
7: Click “Applications”
8: Click on the “AppleScript” folder
9: Open Script Editor”
10: Copy this script into the editor and run it and you’re done.
-- Example list of processes to ignore: {"xGestures"} or {"xGestures", "OtherApp", ...}
property processesToIgnore : {}-- Get the size of the Display(s), only useful if there is one display
-- otherwise it will grab the total size of both displays
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 telltell application "System Events"
set allProcesses to application processes
set _results to ""
repeat with i from 1 to count allProcesses
set doIt to 1
repeat with z from 1 to count processesToIgnore
if process i = process (item z of processesToIgnore) then
set doIt to 0
end if
end repeatif doIt = 1 then
tell process i
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 winPosif (_x < 0 or _y < 0 or _x > screen_width or _y > screen_height) then
set position of window x to {0, 22}
end if
end repeatend tell
end if
end repeat
end tell
Note: After running this script, a weird little white box shows up at the top left of my display. Very odd….but when I reboot, everything is fine.

I'm a web developer, UI/UX specialist and online strategist with over 10 years of experience in the field. I am currently freelancing and am available for hire. I have hands-on experience in all stages of the SDLC. If you or your business needs a web site, could use some help with your online strategy, or if you need to get started with SEM, please feel free to contact me.
I can help you with: Web Site Design and Development, Search Engine Optimization, Search Engine Marketing, Multivariate Testing, Metrics Analysis, Campaign Optimization, Social Site Integration, E-mail Marketing and everything else that has to do with the Web.
I work/haved worked with the following technologies: XHTML, CSS, Javascript, Ajax, JQuery, MySQL, SQL Server, ASP, ASP.Net, Coldfusion, PHP, Wordpress, Flash, Google Analytics, Google Adwords.
[...] that I got this code from somewhere like this, modified slightly for my [...]
@Leon – yeah, I’m aware of the ‘changing resolution’ trick, but this script just got me all excited…
Bummer. I wish I understood Applescript well enough to tinker with it myself.
Thanks tho.
@cflex: not sure how you would make that work. I only use one screen and cannot test this on a 3 screen setup. Another way you could try is to change your display resolution settings on the three screens, apply the changes, then change them back to the original.
OK, I posted earlier that Safari 4.0.4 is immune. I was incorrect. Anything on my 3rd display is immune. I have 3 displays, and the center display is my main display, where my Dock resides. The script will pull everything from the left screen onto the center screen, but ignore windows in the right screen.
Any idea how I can make it work for my right screen as well?
Thanks!
C
Thanks for the awesome script – I use 3 displays, which are always on and connected, but sometimes I’ll toggle my right screen over to my PC temporarily, and during that time I lose access to windows on that screen (the screen has multiple inputs so it can be connected to multiple video sources simultaneously).
This script worked for me with one exception – Safari 4.0.4 seems to be immune to its effects.
I’m running Mac OSX 10.6.2.
Any clue on getting Safari to react like it should?
Thanks again for the script.
Quincy, thanks for the post. I’ve updated the script with your suggestions. The double dashes are in place now and the quotes should also be correct.
You can see from my previous post that there is just no decent way represent regular quotes. They were all converted to curly/angled quotes even where I typed regular straight quotes. Also the dashes got squirrely too. The last set of dashes looks link it is one short and one long with a space between, but really it is/was two shorts with space between. Just bizarre.
This script didn’t work for me initially because the Applescript tags were not correct. The comments at the beginning of the lines that have them should be two regular dashes NOT the one long dash that is displayed. (I’m guess the software on the site change the two dashes into one long dash.
- (one short dashed typed in)
– ( two short dashes typed in)
— (three short dashed typed in )
- – (two dashed with a space between typed in)
The other problem was that the quotation marks displayed are of the angled left/right variety and those don’t work on my mac either. I changed those to regular quotes and got past that error.
” (one double quote typed in)
“System Events” (copied and pasted from above, with angle quotes)
“ ” (one angle quote with a space then one normal quote)
And last but not least the two less than symbols are missing. Just remember that you can have ( A or B or C ) but each piece, A for example must have a comparison (a1 greaterThan a2)
if (_x GREATERTHAN 0 or _y LESSTHAN screen_width or _y LESSTHAN screen_height) then
I substituted words instead of symbols since posting them obviously causes problems. I should also say I’m brand spanking new to the world of macs and apple script so forgive me if I’ve said something dumb and obvious here.
Quincy
you are a frickin superstar, this just saved me hours of wasted time
Genius !!!
I just found another way, no programming:
- open system preferences
- select ‘Displays’
- change resolution to one setting lower
- change resolution back to how it was
All my off-screen windows came back!
that’s really strange. our posts keep getting garbled and truncated. Ignore my last post. Norm’s post is missing a “<”.
Thank you! Once I got this line right it worked.
if (_x screen_height) then
should be
if (_x < 0 or _y screen_height) then
Thank you! I was so frustrated. Now I am not frustrated.
didn’t work for me. there’s a little error.
this line:
if (_x screen_height) then
should really be:
if (_x < 0 or _y screen_width or _y > screen_height) then
with that fix, it worked for me.
Could not have done it myself. Thanks Leon
Holy crap, everything got mangled on my post
there needs to be a ‘<’ between the ‘_y’ and the ’screen_width’
cheers
You saved me, thank you. Found syntax error though -
if (_x screen_height) then
should be
if (_x < 0 or _y screen_height) then
I don’t know applescript, just an educated dart.
again – TY