How To: Get Off Screen Windows Back to your Main Display (MAC OS X v10.5)

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 tell

tell 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 repeat

		if 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 winPos

					if (_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 repeat
			end 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.

48 thoughts on “How To: Get Off Screen Windows Back to your Main Display (MAC OS X v10.5)”

  1. I am having this issue but will this script remove my ability to use multiple monitors as people have mentioned above? If so then it’s useless.

  2. The script worked fine but when I hooked back up to multiple monitors, I no longer had menu bars on each screen like I did before.

    Maverics OS X version 10.9.1
    2009 Macbook Pro

    2.53 Ghz processor. 8GB RAM

    Solid state hard drive.

    Can I somehow undo this?

  3. doesn’t work on 10.7 it says system events got an error access for assitive devices it disabled but i have it checked.

    Any updates?

    Thank you

  4. hi when i do it it says system events got an error access for assitive devices it disabled but i have it checked..

  5. You, sir, are a life saver. I was running up against a deadline when I opened a program that I needed to use, but hadn’t used since I was in a different setup and had two monitors. Now I just had the one and all the windows for this dumb application were over on a non-existent screen! I was going out of my head, my system knew there were not two monitors, so it wouldn’t let me mirror or re-arrange. No other tips would work. But your code did the trick! Thank you so much for taking the time to post this. Again, you are a life saver!

  6. Leon,
    What a GREAT tip. Thanks so much for sharing your knowledge with the Mac community. Keep it coming.
    Judy

  7. Thanks a Billion!!! apple really needs to sort this problem out — you have saved me so much time!!!
    cant thank you enough :)

  8. System Preferences>
    Click Show Displays In Menu Bar>

    When you VPN in and can’t see the other screen then click on the screen icon at the top:

    Turn On Mirroring.

    When you are done then:

    Turn Off Mirroring.

  9. I wish I came across this earlier, my photoshop windows were opening up offscreen and I even resorted to re-installing it but nothing worked. Until now! Thanks a million!

  10. YOU SIR A A GOD!!!! i praise you!!!! i just can’t express how much i love you right now, THANK YOU!! XD

  11. OMG- thank you thank you. I tried for hours to solve the problem myself-I had iMovie open but it was hidden in the upper right of hte desktop and NOTHING i did worked. Thank you for taking the time to post that solution, it actually made me cry. thanks again, seriously!

  12. Works great!
    If you receive the error about assisted devices turned off, just try to close all “visible” applications you don’t need at the moment and run script once again.
    Thank you!

  13. OK, Leon, you are amazing. This solved my problem of having a Photoshop CS4 dialog box off my screen by restoring it. I am using Mac OS X 10.5.8

    Thanks!

  14. I have access for assisted devices turned on but when I run the script it says it is off. What gives?

    gb

    p.s, this is a huge fail on Apple’s behalf. Why can’t they auto move windows to the remaining displays?

  15. This worked the first time with not even a weird white box appearing in the corner! Thank you!!

  16. You saved me, too. Expose, Window > Zoom, Application Expose… nothing was returning my application to the desktop. But this did the trick. Thanks!!

  17. Fantastic Sir. I was beggining to wonder if I would ever see my JDownloader window again. Thanks alot.

  18. Fantastic. I have Vicomsoft FTP Client on OS 10.5.8 and for some reason the ftp connection dialogue shot up and off the top right hand corner of the screen. Using Expose I could see the dialogue but every time I went to click on it the window shot up again.

    I searched a fair bit on Google until I found this script. When I ran it I got an error saying “Definitely” not defined.

    This doesn’t seem to have hurt as everything back to normal now. Thanks again for posting this VERY helpful hint!

  19. @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. :)

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

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

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

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

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

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

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

  27. that’s really strange. our posts keep getting garbled and truncated. Ignore my last post. Norm’s post is missing a “<“.

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

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

  30. Holy crap, everything got mangled on my post :(

    there needs to be a ‘<‘ between the ‘_y’ and the ‘screen_width’

    cheers

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>