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 tellif _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 trytry
tell application “NetNewsWire”
activate
set the bounds of the first window to {90, 0, 1240, 624}
end tell
end trytry
tell application “Mail”
activate
set the bounds of the first window to {90, 658, 926, 1200}
end tell
end try
end ifif _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 trytry
tell application “NetNewsWire”
activate
set the bounds of the first window to {80, 0, 1230, 624}
end tell
end trytry
tell application “Mail”
activate
set the bounds of the first window to {80, 315, 915, 857}
end tell
end try
end if
3 Responses to “Automagically resize your windows”
Leave a Reply
May 24th, 2008 at 9:42 pm
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.
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.
May 27th, 2008 at 9:35 am
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
May 5th, 2009 at 1:08 pm
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: