Need Hosting for a Wordpress site? Get $90 off @ Dreamhost!

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.

  • Digg Me
  • Bookmark me on Del.icio.us
  • Post to StumbleUpon
  • Tweet Me

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

  1. Raymond Ishman says:

    If you use this, multiple monitor support in Mavericks is gone for good!

  2. RI says:

    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. Oliver says:

    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. Eugene says:

    Thank you!

  5. bob says:

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

  6. TJ says:

    WONDERFUL! Thanks so much. It worked great.

  7. Chad says:

    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!

  8. jkubi93 says:

    awesome. helped so much thank you.

  9. Judy Buchanan-Hewitt says:

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

  10. quaid says:

    you saved my life

  11. Goulding says:

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

  12. Dan says:

    Thanks!
    U saved my day :-)

  13. Mike Jenkins says:

    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.

  14. George says:

    Yet another reason to not use a Mac….

  15. Michelle says:

    I love you! You just saved me a trip back to my office in rush hour! My hero…

  16. jesus says:

    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!

  17. Lainer says:

    THANK YOU SO MUCH! That was amazing. I was ready to pull my hair out. This totally worked.

  18. Benjamin says:

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

  19. Noonday says:

    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!

  20. Irbis says:

    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!

  21. Camilla Boman Jensen says:

    THANK YOU!
    :)

  22. chasila says:

    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!

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

  24. CAN says:

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

  25. Gabe Knox says:

    Thank you!

  26. Eric says:

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

  27. Ivan Duffles says:

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

  28. Edwin says:

    The script worked like a charm. I got my lost window back!

  29. adam says:

    Thanks a lot, this saved my day!

  30. Andrew B says:

    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!

  31. [...] that I got this code from somewhere like this, modified slightly for my [...]

  32. cflex says:

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

  33. leon says:

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

  34. cflex says:

    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

  35. cflex says:

    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.

  36. leon says:

    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.

  37. Quincy says:

    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.

  38. Quincy says:

    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

  39. grateful says:

    you are a frickin superstar, this just saved me hours of wasted time

  40. Edmund says:

    Genius !!!

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

  42. Kent Valentine says:

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

  43. Kent Valentine says:

    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

  44. John Fryar says:

    Thank you! I was so frustrated. Now I am not frustrated.

  45. norm says:

    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

  46. jason lome says:

    Holy crap, everything got mangled on my post :(

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

    cheers

  47. jason lome says:

    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

About Me

I'm a web solutions architect with over 15 years of experience working with all sorts of web technologies. 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 new web site or web application please feel free to contact me.

I can help you with: Web Application/Web Site Design and Development, Wordpress Plugin 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: HTML5, CSS, Javascript, Ajax, jQuery, MySQL, SQL Server, ASP.Net, MVC, c#, Entity Framework, Razor, WCF, OData, PHP, Wordpress, Flash, Google Analytics, Google Adwords, Subversion.

Recent Work

  • Attune Communications
  • Bosse Spa & Style
  • Felicello Law
  • Michael E. McCarthy Scholarship Fund
  • Leonard’s Upholstery
  • Telly’s Cafe
  • InformedU
  • The Survey Initiative
  • Amy Bowen Photography
  • Engel & Schultz

Comments

about this site

This site was built using Wordpress, Jquery and Blueprint, along with HTML, Javascript, CSS, and PHP.

Open source scripts from: Magpie RSS, jCarousel.

Feeds from: Yahoo Pipes, Flickr, Twitter, and De.licio.us.

This site is hosted @ Dreamhost.