Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Keyboard shortcut for the green "zoom" button (See related posts)

// Ever since I started using OS X as my main OS (back at version 10.1), I kept wishing for a keyboard shortcut for the green button at the top left of each window. I wanted a quick way to maximize a window. Sadly, such a shortcut never came into being. I finally took the time to write an applescript to do the job. You can paste this script into Script Editor and save it in your ~/Library/Scripts/ folder. I saved my script as "Click Green Maximize Button of Frontmost Window.scpt". I then used QuickSilver's Triggers feature to assign the keyboard shortcut Control-Option-Z to run the script. I picked that key combination because it's easy to press. I remember it by thinking of the Z as standing for Zoom. Get QuickSilver here: http://www.versiontracker.com/dyn/moreinfo/macosx/22549

tell application "System Events"
	if UI elements enabled then
		set FrontApplication to (get name of every process whose frontmost is true) as string
		tell process FrontApplication
			click button 2 of window 1
			--button 2 is the green "zoom" button for all applications
			--window 1 is always the frontmost window.
		end tell
	else
		tell application "System Preferences"
			activate
			set current pane to pane "com.apple.preference.universalaccess"
			display dialog "UI element scripting is not enabled. Check 'Enable access for assistive devices'"
		end tell
	end if
end tell

Comments on this post

SimonDorfman posts on Jan 05, 2006 at 11:17
Check the comments of this thread for other ideas on this topic:
http://www.macosxhints.com/article.php?story=20051227001809626

You need to create an account or log in to post comments to this site.


Click here to browse all 5140 code snippets

Related Posts