Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to resize windows to their vertical maximum Desktop
I don't really like the "Green Plus" for window maximization: it seems random and unpredictable, and is not available with a keyboard shortcut. I wanted a way to maximize a window vertically, in particular Terminals and Finder windows, with a simple keystroke. So I came up with this AppleScript (my first!).

It is fairly inelegant in that it requires you to hard-code your vertical display height (I couldn't find a simple way to query for that, the number is for a 15" PowerBook). It works by finding the current application, coming up with an appropriate Y-size, and setting the foremost window bounds with it.

Sadly, every app seems to mean something different by the window bounds, rather than simply the outside bounds of the window and titlebar. In fact, the Finder is the biggest offender -- the bounds mean something different depending on whether the toolbar is visible or not. I have explicitly coded around the Finder's non-consistent behavior, but other apps may have the same flaw.

To bind it to a keystroke, I use a QuickSilver trigger to run the script, after spending many wasted hours trying to understand why this hint wouldn't work (until I read the comments). I find it most useful in Mail new message windows, Finder windows, and Terminal windows (above all). It doesn't work for X11 windows (which I'd love), and a few non-Apple apps I tried (does nothing for PowerPoint, and messes Word's windows up). I suspect something similar could be done for horizontal or full screen maximize.

Comments, suggestions and improvements welcome.
    •    
  • Currently 2.40 / 5
  You rated: 1 / 5 (5 votes cast)
 
[24,781 views]  

A script to resize windows to their vertical maximum | 17 comments | Create New Account
Click here to return to the 'A script to resize windows to their vertical maximum' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to resize windows to their vertical maximum
Authored by: cfoster on May 05, '05 12:01:23PM

I think this should get the screen size for you:

    
    try
    	set window_info to do shell script
    	"defaults read com.apple.loginwindow | grep -w 'NSWindow Frame About This Mac'"
    	set screen_width to (word 13 of window_info as number)
    	set screen_height to (word 14 of window_info as number)
    on error -- use defaults on failure
    	set screen_width to 1024
    	set screen_height to 768
    end try
    

Unfortunately, I just made the switch to Tiger and so I don't have 10.3 around to find out if this information is also available in the same com.apple.loginwindow domain.

-Colin.



[ Reply to This | # ]
A script to resize windows to their vertical maximum
Authored by: jdsmith on May 07, '05 01:48:30AM

Thanks, that worked in 10.3. Does the script work in Tiger as well?



[ Reply to This | # ]
A script to resize windows to their vertical maximum
Authored by: fiorix on Feb 26, '11 07:36:49AM
I've been using the Spark Daemon for a while to define custom keyboard shortcuts that executes Apple Script on Terminal.app (and any other app) in such a way that Cmd+1 to Cmd+9 switches the current tab to tab N. Today I wrote the following code to vertically maximize the Terminal:
tell application "Finder"
	set _b to bounds of window of desktop
end tell

tell application "Terminal"
	tell front window
		set {_x, _y, _w, _h} to (get bounds)
		set _vz to item 4 of _b
		set bounds to {_x, 10, _w, _vz}
	end tell
end tell
Works fine on 10.6.

[ Reply to This | # ]
A script to resize windows to their vertical maximum
Authored by: Dephex Twin on May 05, '05 12:52:28PM
For screen size, the easiest thing I've found is to download the tiny little command line app called cscreen. Then the command "cscreen" in the terminal will return an easy-to-parse description of your monitor's settings.

---
"Knicks suck, Yankees suck, Mets suck..."
"...Krypton sucks"

[ Reply to This | # ]

A script to resize windows to their vertical maximum
Authored by: mdouma46 on May 05, '05 06:09:28PM
"I don't really like the "Green Plus" for window maximization: it seems random and unpredictable, and is not available with a keyboard shortcut."
Um, can't you just do the following:

System Preferences > Keyboard & Mouse > Keyboard Shortcuts

Under All Applications, click the + to add a new shortcut for Menu Title: "Zoom" (without the quotes), and a Keyboard Shortcut such as Command-Option-Z or whatever else you'd like.

Hope this helps....

[ Reply to This | # ]
A script to resize windows to their vertical maximum
Authored by: jdsmith on May 07, '05 01:51:04AM

That would simply give a keyboard shortcut for the "green plus", in the (relatively few) apps which have a "Zoom" menu item. Try hitting the green zoom button in a Terminal window and you'll see why I'd prefer a *vertical-only* maximize, as this script provides.



[ Reply to This | # ]
A script to resize windows to their vertical maximum
Authored by: n8gray on May 05, '05 07:06:44PM
For Safari, at least, you can use a javascript bookmarklet. I have one that resizes the browser to 1024xScreenHeight. Just make a bookmark and copy this to the address:


javascript:function%20rsz(s,i,w,h,m){if(i.screenX0||i.outerWidth%3Ew||i.outerHeight%3Eh){s.moveTo(0,0);s.resizeTo(w,h)};if(m){s.moveTo(m==1?0:screen.availWidth-w,0);};s.resizeTo(w,h);};rsz(self,window,1024,screen.availHeight,1);

You could probably hack it to leave the width alone and just resize the height. By the way, I totally agree about the green +. It's pretty useless. I wish Apple would add a "Zoom vertically only" option to the system prefs, like you see with unix window managers.

[ Reply to This | # ]

A script to resize windows to their vertical maximum
Authored by: tonygoulding on May 06, '05 11:38:46PM

that's nice, except that it expands the window to the full screen size, trampling over the dock (I have my dock on the left).



[ Reply to This | # ]
A script to resize windows to their vertical maximum
Authored by: qwerty denzel on May 09, '05 07:34:13AM
Just download Apple's sample Safari applescripts here.
Included is this:

tell application "Safari"
	repeat with i from 1 to the count of documents
		do JavaScript "moveTo(0,0);self.resizeTo(screen.availWidth,screen.availHeight)" in document i
	end repeat
end tell


[ Reply to This | # ]
A script to resize windows to their vertical maximum
Authored by: barrysharp on May 08, '05 01:22:08AM

That was a cool tip/hint. THANKs.

---
Regards... Barry Sharp



[ Reply to This | # ]
Awesome!
Authored by: grrl_geek on Aug 31, '05 12:27:07PM
Thanks so much for that bookmarklet. It works in Firefox, too.

I changed the sizes so browser windows are resized to 800x600:
javascript:function%20rsz(s,i,w,h,m){if(i.screenX0||i.outerWidth%3Ew||i.outerHeight%3Eh){s.moveTo(0,0);s.resizeTo(w,h)};if(m){s.moveTo(m==1?0:screen.availWidth-w,0);};s.resizeTo(w,h);};rsz(self,window,800,600,1);
because due to my iBook's low screen resolution, the edges of browser windows would tend to drift off the screen, making it impossible to move or resize them. This pops the window back.

[ Reply to This | # ]
A script to resize windows to their vertical maximum
Authored by: b2barker on May 05, '05 09:21:42PM
You can also set the vertical screen resolution with:
set display_y_size to item 2 of (screen resolution)
The screen resolution event is part of the XTool.osax.

[ Reply to This | # ]
Script does not work with multiple screens correctly.
Authored by: makis on Sep 15, '06 11:58:34PM

Hello, the script seems to work quite ok except I am using multiple monitors (macbook LCD plus external display). When I vertically resize a window with this script I end up with the window maximised but also _moved_ to my primary display. Is there something else that can be done in the apple script to prevent this from happening?



[ Reply to This | # ]
A script to resize windows to their vertical maximum
Authored by: Jim Jones on Aug 16, '07 04:33:24PM

Because I use a few different external monitors, and sometimes only use my actual MacBook display, I was investigating various ways to query the current display's resolution. But, what I found is that simply setting the resolution to something greater than what you actually have causes the window to have the maximum value regardless of what you set. So, in the script that the OP posted here, I simply set the y resolution to 1200 (the value of my greatest display) and it works regardless of which monitor I am using. In fact, I can drag a window from display to display and run the script and it dynamically changes. Here's the line I changed:

set display_y_size to 1200



[ Reply to This | # ]
Problems with running this script and a saved terminal
Authored by: jayjanssen on Sep 17, '07 06:07:44AM
I got the script to work great. I'm using it with terminal.app, and I usually open my terminals with a .term file. This allows me to open a new terminal every time I double-click the .term (or use Quicksilver).

However, after I run this script on a terminal window, I am unable to open any new .term files until I quit Terminal and restart. I am able to open a new terminal with command-n.

Any ideas? I'm on 10.4.10.

[ Reply to This | # ]

Some improvements
Authored by: parki3n on Sep 14, '08 08:24:52PM

I found this script very useful, but I ended up making a few improvements that I wanted to share:

1. I wanted it to maximize both vertically and horizontally.
2. I wanted it to figure out the size of the screen programatically, instead of being hard coded.
3. I also wanted it to take into account the dock size automatically.

Some of the code for this was pulled together from other sites on the web, but it's all documented in the Applescript library help.

tell application "Finder"
     set _b to bounds of window of desktop
     set _display_x_size to (item 3 of _b)
     set _display_y_size to (item 4 of _b)
end tell

set cur_app to (path to frontmost application as Unicode text)
if cur_app ends with ":Finder.app:" then
     set Finder to true
     tell application "Finder"
          set tool_vis to toolbar visible of front window
     end tell
else
     set Finder to false
end if

tell application cur_app
     tell front window
          set {x1, y1, x2, y2} to (get bounds)
          set y1 to 44 (* To account for the toolbar *)
          set x1 to 0
          set x2 to _display_x_size
          if Finder then
               -- FINDER (Finder application returns a strange value, so this gets the correct info)
               if tool_vis then
                    -- This section retrieves the vertical height of the Dock
                    tell application "System Events" to tell process "Dock"
                         set _dock_dimensions to size in list 1
                         set _dock_height to item 2 of _dock_dimensions
                    end tell
                    set y2 to (_display_y_size - _dock_height)
                    --set y2 to _display_y_size
                    -- OLD: set y1 to 83
               else
                    set y2 to _display_y_size
               end if
          else
               -- NOT FINDER
               set y2 to _display_y_size
          end if
          set bounds to {x1, y1, x2, y2}
     end tell
end tell




[ Reply to This | # ]
A script to resize windows to their vertical maximum
Authored by: AlgebraicSpore on Jan 13, '09 01:16:16PM

This script works well for me, except that it doesn't work in all apps (i.e. Firefox, Thunderbird, Emacs.app). Does anyone know how to get the apple script to work in these apps or is there no way to have an applescript communicate directly with them?



[ Reply to This | # ]