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


Click here to return to the 'Create a keyboard shortcut for the maximize button' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create a keyboard shortcut for the maximize button
Authored by: redsweater on Jan 03, '06 09:11:49AM
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 Jan 03, '06 01:37:57PM

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 | # ]