» Automagically resize your windows

Automatically resizing your application windows based on resolution is a topic that I find pretty interesting and has been covered by two of my favorite sites here and here.  The script was originally written by Jeff Kelley on his blog.  After playing with the script for a few hours I finally got something together that I like.  I wanted to post my version of the script and a few notes for people to review if they want to tweak the original script.

I will start by saying I like my windows to be as small as possible so I can have as many open apps visible at a time; but here are a few things I ran into…

1) The quotation marks are not copying correctly from the site into script editor so you will have to replace them manually prior to compiling.

2) The format of the bounds for the windows is also useful to know. First notice that the very top of the desktop (just below the menu bar) is y=0 and the very left the desktop is x=0. The window bounds follow this format (dist x left, dist y top, dist x right, dist y bottom). Distance from x(y)=0 to [window side]. If that doesn’t make sense I’ll try to make a visual diagram.

3) You can quickly find the values of distances using CMD+SHIFT+3 and looking at the coordinates as you drag the selector around the screen.

4) Because of how I like my windows I found it easier to do all of the resizing within two if-statements. ie. If Width = 1920 size the windows this way, If Width = 1440 size the windows that way.

View the full entry to see my script.

tell application “Finder”
set _b to bounds of window of desktop
set _width to item 3 of _b
set _height to item 4 of _b
end tell

if _width is equal to 1920 then

try
tell application “Safari”
activate
set the bounds of the first window to {940, 0, 1790, 1200}
end tell
end try

try
tell application “NetNewsWire”
activate
set the bounds of the first window to {90, 0, 1240, 624}
end tell
end try

try
tell application “Mail”
activate
set the bounds of the first window to {90, 658, 926, 1200}
end tell
end try
end if

if _width is equal to 1440 then

try
tell application “Safari”
activate
set the bounds of the first window to {450, 0, 1300, 900}
end tell
end try

try
tell application “NetNewsWire”
activate
set the bounds of the first window to {80, 0, 1230, 624}
end tell
end try

try
tell application “Mail”
activate
set the bounds of the first window to {80, 315, 915, 857}
end tell
end try
end if

3 thoughts on “» Automagically resize your windows”

  1. I have a very similar script, though I’m looking to make a few changes in it. Mine works nearly the same to yours, though it doesn’t activate each app first, and it also checks to see if they’re running first, so it doesn’t launch apps if they don’t need to be launched.

    — Determine what the screen width is
    tell application “Finder”
    set screenBounds to bounds of window of desktop
    set screenWidth to item 3 of screenBounds
    end tell
    if screenWidth is equal to 3120 then set screenChoice to “Dual Screen”
    if screenWidth is equal to 1440 then set screenChoice to “Single Screen”

    — Check what apps are running
    tell application “System Events”
    set iTunesRunning to count (every process whose name is “iTunes”)
    set NetNewsWireRunning to count (every process whose name is “NetNewsWire”)
    set SafariRunning to count (every process whose name is “Safari”)
    set MailRunning to count (every process whose name is “Mail”)
    end tell

    — Single Screen positions
    if screenChoice is “Single Screen” then
    if iTunesRunning is 1 then
    tell application “iTunes”
    set minimized of front browser window to true
    set bounds of front browser window to {989, 831, 1440, 900}
    set minimized of front browser window to false
    set bounds of front browser window to {0, 22, 1440, 900}
    end tell
    end if
    if NetNewsWireRunning is 1 then
    tell application “NetNewsWire”
    set bounds of front window to {0, 22, 1440, 900}
    end tell
    end if
    if SafariRunning is 1 then
    tell application “Safari”
    set bounds of every window to {0, 22, 1440, 900}
    end tell
    end if
    if MailRunning is 1 then
    tell application “Mail”
    set bounds of front window to {0, 22, 1440, 900}
    end tell
    end if
    end if

    — Dual Screen positions
    if screenChoice is “Dual Screen” then
    if iTunesRunning is 1 then
    tell application “iTunes”
    set minimized of front browser window to true
    set bounds of front browser window to {1680, 835, 2131, 900}
    set minimized of front browser window to false
    set bounds of front browser window to {1680, 0, 3120, 900}
    end tell
    end if
    if NetNewsWireRunning is 1 then

    tell application “NetNewsWire”
    set bounds of front window to {1680, 0, 3120, 900}
    end tell
    end if
    if SafariRunning is 1 then
    tell application “Safari”
    set bounds of every window to {83, 22, 1546, 1046}
    end tell
    end if
    if MailRunning is 1 then
    tell application “Mail”
    set bounds of front window to {1680, 0, 3120, 900}
    end tell
    end if
    end if

    I used to use a dialog box to select which settings to use, but thanks to inspiration from your script, I now use the bounds of the desktop to determine screen width.

    Eventually, I’d like to use the property stuff in Applescript to save the initial window positions, so it’s more flexible for other users using different sets of window positions.

  2. Adam,

    I’m glad my script was useful to at least somebody! I definitely consider myself a scripting n00b so I mostly hack away at these like a blindfolded, machete-wielding jungle explorer. I have to admit I’m going to have to steal your stuff on checking for running applications – personally, I haven’t run into that yet because my three “defaults” are always running. However, it’s a lot more elegant than just assuming they are running so thank you for the input!

    aron

  3. The bounds of a window is a rectangle, consisting of left, top, right, bottom values. Setting the screenWidth to the right value of the desktop’s window will only work as expected if the menu bar is on the left-most monitor in a multi-monitor situation (which isn’t the case in my default multi-monitor setup).

    Change the screenWidth calculation to the following to get a reliable screenWidth measurement, regardless of where your menu bar is:

    set screenWidth to ((item 3 of screenBounds) – (item 1 of screenBounds))

Leave a Reply

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