Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

Create a keyboard shortcut for the maximize button System
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
  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

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...]
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[63,288 views]  

Create a keyboard shortcut for the maximize button | 27 comments | Create New Account
Click here to return to the 'Create a keyboard shortcut for the maximize button' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Create a keyboard shortcut for the maximize button
Authored by: earthsaver on Tue, Jan 3 2006 at 7:20AM PST
Not working for me. I removed the portion about enabling control for assistive devices, because that's always enabled. Script causes window 1 to go out of foreground for half a second, then return unchanged.

What am I missing?

---
- Ben Rosenthal
Q16 1.25 - Tiger

[ Reply to This | # ]
Create a keyboard shortcut for the maximize button
Authored by: redsweater on Tue, Jan 3 2006 at 7:27AM PST
Nice! I liked the idea so much, I immediately installed it (works great with FastScripts, too). I was able to simplify the script quite a bit and remove the dependency on UI Scripting:


tell application "System Events"
	set frontApp to first application process whose frontmost is true
end tell

tell application (name of frontApp)
	set zoomed of window 1 to not (zoomed of window 1)
end tell

Hope this helps!

---
--
Daniel Jalkut
http://www.red-sweater.com/

[ Reply to This | # ]

Create a keyboard shortcut for the maximize button
Authored by: redsweater on Tue, Jan 3 2006 at 7:40AM PST
Update: it seems that my solution doesn't work universally. But the UI scripting version doesn't, either. For instance my version completely fails in Calculator, while the original script works. But my script "does something" in iTunes while the UI scripting version produces a scripting error.

I guess this is going to be hit-or-miss no matter what you choose. The good news is both methods work on the vast majority of "normal apps" I've tried.


---
--
Daniel Jalkut
http://www.red-sweater.com/

[ Reply to This | # ]
Create a keyboard shortcut for the maximize button
Authored by: SimonDorfman.com on Tue, Jan 3 2006 at 9:10AM PST
Thanks for your help on this Daniel. I tried testing my script on more applications and I realized it doesn't work with Photoshop. I was trying to alter your script so it would get the name of the front window. I thought that might fix it and make it work with all applications. But I'm having some trouble. Here's what I got:

tell application "System Events"
	set frontApp to first application process whose frontmost is true
end tell

tell application (name of frontApp)
	set frontWindow to name of front window
	set zoomed of frontWindow to not (zoomed of frontWindow)
end tell
but it's not working. I don't really understand the set zoomed of window 1 to not (zoomed of window 1) line, but I was thinking maybe saving frontWindow as string or alias, but those didn't work either. Any ideas? Do you think I'm on the right track?

[ Reply to This | # ]
Create a keyboard shortcut for the maximize button
Authored by: jacobolus on Fri, Jan 6 2006 at 3:28AM PST
not (zoomed of window 1)
will return the opposite of (zoomed of window 1), so daniel's code just toggles the zoom

[ Reply to This | # ]
Create a keyboard shortcut for the maximize button
Authored by: whoadoggy on Tue, Jan 3 2006 at 7:44AM PST
I recently did this by making a keyboard shortcut (cmd-opt-Z) to select the menu item zoom. Works in all apps I have tested this far.

What I would really like is to be able to switch the behavior of double clicking in the title from minimizing the window to zooming it. Having to work sometimes on another platform has ingrained this into muscle memory. Any one know how to do that?


[ Reply to This | # ]
Problem with this idea is
Authored by: gullevek on Fri, Jan 6 2006 at 7:32AM PST
that it zooms ALL windows of a group instead of just the frontmost one. I don't know why, because Minimize works only on the frontmost one. Perhaps a bug?

[ Reply to This | # ]
Keyboard Shortcuts?
Authored by: guardian34 on Tue, Jan 3 2006 at 7:40AM PST
Why not use "Keyboard Shortcuts" under the Keyboard & Mouse preference pane [of System Preferences]?

[ Reply to This | # ]
Keyboard Shortcuts?
Authored by: TvE on Tue, Jan 3 2006 at 7:48AM PST
That is excatly what I have done - CTRL-Z = Zoom.
Only downside is that it only works for applications that has a "Zoom" menuitem - but most do.

Calculator does not, since clicking the green button changes "mode" - but luckily Apple has pre-made shortcuts for these actions (CMD-1, CMD-2 & CMD-3)

[ Reply to This | # ]
Keyboard Shortcuts?
Authored by: PCheese on Tue, Jan 3 2006 at 7:56AM PST
You may want to try command-control-Z; that's the Zoom shortcut for iTunes.

[ Reply to This | # ]
Keyboard Shortcuts?
Authored by: TvE on Thu, Jan 5 2006 at 12:49PM PST
Nope - not as delivered from Apple

[ Reply to This | # ]
In the terminal
Authored by: hombre on Tue, Jan 3 2006 at 6:30PM PST
Most apps have either "Zoom" or "Zoom Window" so I use the following:
defaults write NSGlobalDomain NSUserKeyEquivalents '{"Zoom" = "@^Z"; "Zoom Window" = "@^Z"; }'
That sets the keyboard shortcut to Cmd-Ctrl-Z for almost all apps.

[ Reply to This | # ]
terminal vs. GUI
Authored by: hypert on Wed, Jan 4 2006 at 8:12PM PST
Nice hint all around!

I tried this terminal command, and it works perfectly. I especially like seeing the keyboard shortcut in the real menu.

One question: why doesn't this change show up in the Keyboard & Mouse preference pane? I can set other shortcuts there (like Cmd-B to "Show All Bookmarks" in Safari). Since I'll never remember this nifty "defaults" command, how can I set (or view this setting) this through a GUI?

I was hoping Keyboards would be the place, but maybe it won't show shortcuts that weren't created from inside Keyboard & Mouse?

[ Reply to This | # ]
What am I doing wrong?
Authored by: hamarkus on Tue, Jan 3 2006 at 9:36AM PST
I added cmd^Z with the menu name 'Zoom' to the keyboard shortcuts (for all apps). But when I try it, I only get an error beep, and I have tried it in several apps which have the 'Zoom' menu entry.

Do I have to enter something like 'Window-Zoom' or what am I missing?

[ Reply to This | # ]
What am I doing wrong?
Authored by: pub3abn on Tue, Jan 3 2006 at 2:02PM PST
I am having the same difficulty.

[ Reply to This | # ]
What am I doing wrong?
Authored by: kostia on Tue, Jan 3 2006 at 4:47PM PST
Keyboard shortcuts set in System Preferences will only work with applications launched after the setting is applied, not in applications that were already running. You will see the command-control-Z shortcut notation in the Window menu next to Zoom for applications launched after you set this shortcut up.

[ Reply to This | # ]
Create a keyboard shortcut for the maximize button
Authored by: redsweater on Tue, Jan 3 2006 at 9:11AM PST
OK - I've taken the opposite tack of my previous script. By the way - I noticed that using the keyboard shortcut "opt-Z" messes up some apps - iTunes in particular, since it behaves differently when the option key is held down while zooming!

This script will try 3 methods of zooming, in the following order:

1. Zoom by directly changing the "zoomed" attribute on the window. 2. Zoom by selecting a Zoom menu item from the Window menu. 3. Zoom by clicking the zoom button on the window.

This should make a pretty compatible script which zooms in the quickest way possible (direct attribute) when possible, and otherwise resorts to UI scripting methods.

I also include a section at the top to add special cases for particular apps. In particular, iTunes doesn't seem to respond well to the direct attribute setting, so I override it.

Kind of overkill, but it is handy to have something that "almost always works."


-- A script to automatically zoom the frontmost window. 
-- © 2006 by Daniel Jalkut, Inspired by:
--
-- http://www.macosxhints.com/article.php?story=20051227001809626&lsrc=osxh
--

tell application "System Events"
	set frontAppName to name of first application process whose frontmost is true
end tell

set tryZoomedAttribute to true
set tryMenuScripting to false
set tryButtonScripting to false
set allMethodsFailed to false

-- Special cases. For Applications whose behavior we know responds to one or the other
-- method, force that method here.
if (frontAppName is equal to "iTunes") then
	set tryZoomedAttribute to false
	set tryMenuScripting to true
end if

if (tryZoomedAttribute is equal to true) then
	tell application frontAppName
		try
			set zoomed of window 1 to not (zoomed of window 1)
		on error
			set tryMenuScripting to true
		end try
	end tell
end if

-- Make sure the user has UI scripting enabled before we go on...
if ((tryMenuScripting is equal to true) or (tryButtonScripting is equal to true)) then
	tell application "System Events"
		if UI elements enabled is false then
			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
end if

if (tryMenuScripting is equal to true) then
	tell application "System Events"
		tell process frontAppName
			try
				click menu item "Zoom" of menu of menu bar item "Window" of menu bar 1
			on error
				set tryButtonScripting to true
			end try
		end tell
	end tell
end if

if (tryButtonScripting is equal to true) then
	-- UI Scripting method:
	tell application "System Events"
		try
			tell process frontAppName
				click button 2 of window 1
			end tell
		on error
			set allMethodsFailed to true
		end try
	end tell
end if

if (allMethodsFailed is equal to true) then
	display dialog "I'm sorry, I couldn't figure out how to zoom this window."
end if

---
--
Daniel Jalkut
http://www.red-sweater.com/

[ Reply to This | # ]

Create a keyboard shortcut for the maximize button
Authored by: julian1008 on Tue, Jan 3 2006 at 1:37PM PST
you can use an applescript for this in iKey. but in iKey it is easier to use the command designed just for zooming.
http://www.scriptsoftware.com
julian

[ Reply to This | # ]
An alternative solution which ALWAYS works
Authored by: TimBonnici on Tue, Jan 3 2006 at 4:14PM PST
The other alternative is to use Peter Maurer's Witch which was apparently born in response a suggestion made by robg according to this macosxhints article. It's donationware and works nicely. I've got it tied to Option-Tab.

[ Reply to This | # ]
Create a keyboard shortcut for the maximize button
Authored by: baba on Tue, Jan 3 2006 at 5:54PM PST
Somewhat related to this, I've been wondering how to counter what I see as a design flaw in some apps: to open to full screen by default. I understand there are bound to be carry-over habits for folks migrating from the Windows world, but to me, this is like reading a book with the page only millimeters from one's face, and it runs counter to the sublime clarity and consistency of the Apple interface. (Though I acknowledge that has been degrading somewhat of late.) I always want to be able to simultaneously refer to the content of other open documents, whatever the application -- just as I might scan documents on a physical desktop.

Even for those few times when I know I'm going to be reading only -- and only one -- document for an extended period, I won't necessarily render it full-screen, since the text block then becomes too wide for comfort. Granted, I'm a text-based creature, but I like my GUI to stand on it's own and not to unneccesarily hew to the limitations of the command line -- to say nothing of the Windows gooey.

Does anyone know of a way, say, to correct Acrobat Reader's wayward ways?

[ Reply to This | # ]
Create a keyboard shortcut for the maximize button
Authored by: icerabbit on Wed, Jan 4 2006 at 6:30PM PST
You mean the maximize button actually works in OS X?

One of my longest outstanding gripes with OS X is that maximizing does not work with the Finder, Safari, Preview, iTunes, Address Book, ... to name a few of the most prominent ones.

Does this script bypass whatever Apple didn't program into the apps to allow true maximizing, rather then zoom state switching?

[ Reply to This | # ]
Create a keyboard shortcut for the maximize button
Authored by: osxpounder on Thu, Jan 5 2006 at 12:11PM PST
No, it's just "zoom state switching", as you put it -- nicely described, btw. As a switcher who came on board with the first OSX version, it took some getting used to -- the fact that Mac software in general doesn't 'maximize' to fill your screen. Instead, it usually chooses a smart window size. I was constantly resizing my windows.

As I got older and more experienced, I realized I like the OSX method better. It turns out that really wide windows just take longer to read, and it's easier to lose your place on really wide blocks of text.

There are just a few apps I use that I really, really want to maximize, and they tend to be graphics apps with keyboard shortcuts or other controls that can maximize the screen, in sense, such as Photoshop's full screen modes.

I love this hint thread! Thanks so much for that Terminal command! I'm already putting it to work as I pore through scads and scads of Finder windows.

---
--
osxpounder

[ Reply to This | # ]
Create a keyboard shortcut for the maximize button
Authored by: GaelicWizard on Fri, Jan 6 2006 at 8:52AM PST
The maximise button works for me in all the apps of listed. Perhaps you misunderstand its function, or just want something different. The Zoom button widens the window to fit the contents, rather than taking over the screen to display whatver may or may not require that much space. If you want windows cruft dating back to a single application windowing interface, I'm sure there are hacks you can get to simulate that. iThink that there is a way to get a single-application mode out of the Dock (i.e. when you switch from one to the other, the previous one hides itself).

JP

---
Pell

[ Reply to This | # ]
Create a keyboard shortcut for the maximize button
Authored by: markwm on Tue, Apr 11 2006 at 4:35PM PDT
thanks for the excellent tip!

[ Reply to This | # ]
Keyboard Shortcut
Authored by: Blacktiger on Thu, Jan 5 2006 at 10:38PM PST
I use command-m to minimize and command-shift-m to maximize.

---
Concentrate on the Solution, not the Problem

[ Reply to This | # ]
Create a keyboard shortcut for the maximize button
Authored by: sabi on Mon, Jun 5 2006 at 2:43AM PDT
Here's a script that works a bit more reliably (tested it in Safari, Finder, Script Debugger, VLC, ...). It matches the window more accurately, not grabbing floating windows, and matches the button more accurately—in some apps, the zoom button is button 1.

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)
(The above should all be one line; I just split it for readability.)

[ Reply to This | # ]
Create a keyboard shortcut for the maximize button
Authored by: FattyMoBookyButt on Wed, Jun 6 2007 at 6:35AM PDT
I'm trying to run this from the Scripts drop-down in my menu bar. Is there a way to select the triggering app? Like last used app, or last accessed by User?
tell application "System Events"
    set frontApp to (name of first application process whose frontmost is true) as string
    display dialog "frontApp: " & frontApp
end tell
This will returns "System Events" if you run the script directly...which is boo.

[ Reply to This | # ]