Create Zoom Shortcut in Mac OS X Terminal
So lately I’ve been getting into this flow of wanting to make a terminal screen full-screen when I need to focus or read long lines. And I’ve been getting sick of having to use the mouse to push the green plus sign to toggle this.
I did a quick search and found an Apple Script that will work for Terminal and TextMate, which are my bread and butter, respectively.
-- 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
As they suggest you’ll want to add it as a trigger via Quicksilver. This is where the article lacks information about how to do this so I give that here. I assume you’re using Quicksilver.
- Create a folder ~/Library/Scripts (if you don’t already have one)
- Copy the above script and paste it into Script Editor.
- Save that script as Green Zoomer.scpt in your ~/Library/Scripts folder.
- Use the Quicksilver keyboard shortcut Command + ; to bring up the Catalog.
- Click Custom on the left hand side, then on the bottom right you’ll see the plus sign to add a Source.
- Click that plus sign and choose File & Folder Scanner.
- Use the keyboard shortcut Command + Shift + G to type in a manual path.
- Type in ~/Library/Scripts, click Open.
- Click on the refresh icon in the bottom menu to make sure Quicksilver picks up the new script you added.
- Use the Quicksilver keyboard shortcut Command + ‘ to bring up the Triggers.
- Click the plus sign at the bottom and choose HotKey.
- The Select an item dialog box will appear or you can make it appear by clicking on the new trigger you’ve added.
- Type in the first field Green Zoomer and Quicksilver will pickup the file you created, and give it a default action of Run. That’s what we want.
- Click Save and you’re ready to zoom!
My Firefox browser would give me the error ‘UI element scripting is not enabled. Check ‘Enable access for assistive devices’ when I tried to zoom it.
Daniel’s script even apologizes for the error. But no apology is necessary, because OS X pops up Universal Access and you can just click on the Enable access for assistive devices check box and you’re good.
Thanks Simon for the original and Daniel for the rewrite!
2 Responses to Create Zoom Shortcut in Mac OS X Terminal
Leave a Reply Cancel reply
You must be logged in to post a comment.
Lifestream
-
Published Goodbye Dear Friend.— January 23rd via filmprog.com
-
Committed to filmprog/rubyhard.— January 21st via GitHub
-
Committed to filmprog/rubyhard.— January 21st via GitHub
-
Committed to filmprog/rubyhard.— January 21st via GitHub
-
Shared Learn Ruby the Hard Way .— January 19th via GoodReads
-
Committed to urug/urug.github.com.— January 11th via GitHub
-
Github







[...] 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 [...]
Alternative, and with much less work, you could…
1. Open the “Keyboard & Mouse” preference pane.
2. Click on the “Keyboard Shortcuts” tab.
3. Scroll down in the list to “Application Keyboard Shortcuts”.
4. Hit + to create a new one.
5. In the dialog:
– Application: Choose the application of your choice (in this case, it sounds like you want it for all applications… though you could create two entries for Terminal and TextMate if you only wanted it for those).
– Menu Title: Zoom
– Keyboard Shortcut: Press Cmd+Shift+G (or whatever you want)
There you go.