Create a keyboard shortcut for the maximize button

Jan 03, '06 06:12:00AM

Contributed by:

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. Here it is:

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
    tell application "System Preferences"
      set current pane to pane ""
      display dialog "UI element scripting is not enabled. Check 'Enable access for assistive devices'"
    end tell
  end if
end tell

You can paste the above script into Script Editor and save it in your ~/Library/Scripts/ folder (or anywhere else you'd like). 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. Woot! I'm so freakin' happy. It's the little things in life, ya know?

[robg adds: This script worked as described; I tested it in Butler's AppleScript tool...]

Comments (29)

Mac OS X Hints