Wednesday, March 10, 2010

rescue off-screen windows with applescript

i work with dual screens a lot on my macbook specially when i’m at home. every once in a while i would be in too much of a hurry to remove my vga display adapter or return windows to the main screen before putting my macbook to sleep. as a result, i have some windows that are off-screen when my macbook wakes up.

it happened to me again this morning so i finally decided to do something about it. i asked my friend google to see if there was a quick solution i could use. turns out it’s a pretty common occurrence and this mac rumors thread i found had some possible solutions:

  • use Windows -> Zoom
    • doesn’t work if the application did not implement this like keepass and opera (my problem window)
  • gather windows button
    • this only appears when you have a second display attached. if that were the case, i wouldn’t be having this problem in the first place :)
  • spaces + expose
    • doesn’t really work. even if you are able to drag the preview window from one space to another, once you revert to the normal view the window returns off screen only this time in the current space you dragged it into.
so no solutions so far, at least none that worked for me.

fortunately, at end of the same thread someone wrote that it was possible to do it using applescript. he had actually posted some script but he mentioned that running the script had some sort of side effect that could be only be cleared by a reboot. i rarely reboot my macbook so this was not an option for me but it did get me thinking that i could probably write a quick script that would solve my problem. it won’t be a generic solution but it will be a quick an easy solution.

after a bit of research i was able to write a very short applescript that solved the problem and here it is:
tell application "Opera"
activate
set the bounds of the first window to {100, 100, 500, 500}
end tell
it doesn’t really matter what the bounds were as long as they were within the main screen. after running the script my opera window was finally on-screen and all that was left to do was resize the window. problem solved :)

Labels:

0 Comments:

Post a Comment

<< Home