Move All Windows To Your Main Screen…

ApplescriptSo, you’ve got more than one screen? Life is good with all that wonderful screen real estate, then BAM… You end up back with just your main screen, but your applications have left their windows on those other displays, far out of your reach…

Let’s fix that. This little script simply goes and tells all of your applications to get their act together, to move their window’s to the main display.

You’ll need access for assistive devices turned on, which you can do by going in to System Preferences, Universal Access. At the bottom check the box for “Enable access for assistive devices”.

As it is, the script will tell all applications currently running, that if they have a window that is entirely on the main display - to move it to the top left of the screen.

You may have some applications which keep windows off screen on purpose, if you experience any strange behavior with these applications you can exclude them from the applications which get checked by adding their name to the “processesToIgnore” list at the top of the script. There is an example to show how the list should look in the comment right above it. Be sure to use the exact name of the application.

Lastly, if you have more then one display attached when this script is ran it will basically do the same thing, but windows on other screens will not be moved to the main display, only windows outside the range of all current displays.


9 Responses to “Move All Windows To Your Main Screen…”

  1. 1 mooncaine

    Brilliant idea. Could you write a script that would gather all the windows to the main display, even if there are other displays attached?

  2. 2 Jonathan Laliberte

    AFAIK, there is no way to get the size of the main display with Applescript (not easily anyway). The current Finder block gets the size of the desktop, which is going to be the size of all connected displays. The following change would accomplish what you are asking for though:

    At the top of the script, remove the Finder tell block:
    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

    replace it with:
    set screen_width to
    set screen_height to

    So, if your screen resolution is 1440×900, you would have
    set screen_width to 1440
    set screen_height to 900

  3. 3 mooncaine

    Thanks for that, because it did give me something useful. I made a copy of your script, called “gather windows to main display”, and used your suggested code block, except I set it for 800 and 600, so that the windows definitely cluster near the top left corner, no matter what screen res I choose [I change that setting often]. Great! Thanks!

    I renamed the original version to “move offscreen windows to the main display” so I won’t be confused later — I often run my MBP attached to a 2nd monitor.

  4. 4 David Brake

    Thanks - does just what I need (once I made the fix mooncaine asked for). And I can confirm it works on Leopard (in case there was any doubt).

    Dumb question I know but how can I make the script into a mini-app so when I double-click on it it runs rather than launching the editor from which I have to choose “run”?

  5. 5 Jonathan Laliberte

    David,
    Open the script in Script Editor, go to File->Save As…
    Select File Format: Application, I recommend turning/leaving off all the check boxes presented.

  6. 6 Hendel

    Thanks for this - terrific solution to my problem. I normally run Mail.app on my second monitor, but haven’t found a VNC client that will let me access it remotely. When I’m out of town and forgot to push Mail over to the main monitor before I left, I’ve been stuck. Your script works great (though I had to use the modification to set screen size).

  7. 7 Geoffrey Grosenbach

    Works perfectly for my MacBook Air and an occasional external monitor. I call it with LaunchBar.

    Thanks!

  8. 8 Dan Harkless

    You rock. This is one of those occasional areas where Mac OS sucks compared to Windows in not having a native solution for this issue, but this script takes care of that — thanks!!

  1. 1 Life, it is a Travesty… » links for 2007-10-24

Leave a Reply