OSX Zoom

[Edit: 15th July 2011: RightZoom fixes this problem well.]

One of the things I still find annoying about OSX is the green window zoom button. I want it to operate like the min/maximise button in Windows, and this script achieves that for me, in Terminal at least.


[EDIT: 2008-12-05]

From “How to maximize Safari windows?”
And “Need a better way to resize windows, dragging the lower right corner doesn’t cut it.”
And “Finder window to max shortcut?”
And “Add new or change green button?”   

And Window Size/Position on Different Monitors

And “Create a keyboard shortcut for the maximize button”

There are also some interesting comments on “Make utility Terminal windows less intrusive” regarding com.apple.Terminal.plist

WinLocX 0

WinLocY 0

WinLocULY 746


Download UI Element Inspector 



tell application "System Events" to click (first button whose subrole is "AXZoomButton") of (first window whose subrole is "AXStandardWindow") of (first process whose frontmost is true)


tell application “Safari”

set props to properties of front window

end tell


tell application “System Events”

set theProcesses to every process whose visible is true
repeat with theProcess in theProcesses
tell theProcess
set theWindows to every window
repeat with theWindow in theWindows
set theButtons to (buttons of theWindow)
repeat with theButton in theButtons
if (subrole of theButton) is "AXZoomButton" then click theButton
end try
end repeat
end repeat
end tell
end repeat
end tell

tell application "System Events"
	set app_name to name of the first process whose frontmost is true
end tell
tell application "System Events" to tell process app_name
	tell front window
		set position to {0, 0}
		set size to {1280, 1024}
	end tell

		click menu item "Zoom To Fit" of menu 1 of menu bar item "View" of menu bar 1
	end try
end tell

tell application "Finder"
	set {d1, d2, d3, d4} to (desktop's window's bounds)
	set margins to {d1 + 10, d2 + 54, d3 - 10, d4 - 148}
	set bounds of every window to margins
	--replace the previous line with the following for just the front window:
	--set bounds of window 1 to margins
end tell


tell application “Safari” activate –get bounds of front window set bounds of front window to {0, 22, 1024, 768} end tell

Any application can be made minimally scriptable by setting the “NSAppleScriptEnabled” key of its Info.plist file to string “YES” (or equivalent boolean ‘Yes’).
Secondly, it responds to ‘size’ and ‘position’ for windows when controlled by System Events. If you want dynamic instead of hard-wired use the ‘click’ command:
set apli to Firefox
tell application System Events to tell application process apli
tell first window
set size to {1622, 1000}
set position to {0, 22}
click button 2
end tell
set frontmost to true
end tell
on error
end try

tell application “System Events” to set applname to (name of (some process whose frontmost is true)) as text
— display dialog applname — diagnostic only
if applname = “Finder” then return
tell application applname to set bounds of window 1 to {0, 22, 1200, 1000} — for 1680 x 1050 monitor
on error
tell application “Finder” to beep
end try


tell application "System Events" to set applname to (title of (some process whose frontmost is true)) as text


tell application “Safari”
tell document 1 to do JavaScript “javascript:self .moveTo(0,0);self.resizeTo(screen.availWidth,screen.availHeight);”
end tell



tell applicationSafari
set rignewBoffset to 180 offset to the left for large screen
tell (do shell script/usr/sbin/system_profiler SPDisplaysDataType | grep Resolution“) to set {newR, newB} to {word 2 as number, word 4 as number}

set newT to 22
if newR > 800 then
set newL to 593 – (rignewBoffset)
set newR to newR – (rignewBoffset)
set newL to 0
end if
end tell
tell application (path to frontmost application as Unicode text)
tell application “System Events”
set front window‘s bounds to {newL, newT, newR, newB}
end tell

Some applications use ‘document’ instead of ‘window’. You might want to put some more options in the try block to improve performance.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s