Run Applescripts with Keyboard Shortcuts
In the Keyboard and Mouse section of System Preferences there is a Keyboard shortcuts tab that allows you to assign a keyboard shortcut to any menu item. This is great, but unfortunately it doesn’t work everywhere.
The main loss I notice is being unable to assign keyboard shortcuts to scripts in the scripts menu, which would actually solve the entire problem because you could just create scripts to replicate the functionality of any menu item that doesn't want to have a keyboard shortcut. Luckily you can use Quicksilver to assign keyboard shortcuts to AppleScripts. (or anything else). Listed below are 10 AppleScripts to perform lots of tasks that are much more convenient to do quickly with a keyboard shortcut.
Quicksilver is probably one of the most versatile applications for Mac OS X so I won't try and explain everything it does. For our purposes, we only need to use the "Triggers" part, which is accessible from the Quicksilver preferences. If you want to know more about Quicksilver check out the official "What is Quicksilver", or read through Dan Dickinson's "QuickSilver - A Better OS X In Just 10 Minutes".
For each of the AppleScripts below, this is the process you need to go through to assign a keyboard shortcut.
- Open up AppleScript Editor (located in Applications/Utilities) and paste in the script. You can test it works by clicking Run.
- Save the script in the Scripts folder, located in the Library in your user folder.
- Open up the Triggers panel in Quicksilver (Command-' when quicksilver is visible). If you don't already have Quicksilver, you can download it for free from here.
- Click the plus (+) at the bottom, and choose HotKey from the menu to create a new trigger.
- Start typing the name of the script and it should appear in the box. Alternatively you can just drag it into the box from the Scripts folder. Click Save.
- Assign a keyboard shortcut by double-clicking on the trigger column, and typing the shortcut.
These are just the scripts that I could think of off the top of my head. If you have any others that work well with a keyboard shortcut please share them in the comments.
1. Turn AirPort on and off
The two separate scripts that you need to use are below. It's pretty obvious which is which. As explained above, paste each one into a script editor and save as "Airport Off" and "AirPort On" in the Scripts folder.
do shell script "networksetup -setairportpower off"
do shell script "networksetup -setairportpower on"
2. Run Time Machine backup now
do shell script "/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper & “
3. Eject All Disks
To eject all disk images, flash drives, external hard drives, CDs and DVDs (i.e. everything):
tell application "Finder" to eject (every disk whose ejectable is true)
To ignore CDs and DVDs:
tell application "Finder" to eject (disks where free space is not 0)
To ignore large drives (like a Time Machine backup). This is good to get rid of all the mounted disk images:
tell application "Finder" to eject (every disk whose ejectable is true and local volume is true and physical size & lt; 1.0E+9)
4. Set colour labels in the Finder
You will need to create one script for each colour, and assign a different keyboard shortcut to each (or just the colours you use regularly). Command-Option-1, Command-Option-2 etc. might work well. The script works with multiple files selected too.
tell application "Finder" activate set selected to selection set colour to 2 repeat with n_file in every item in selected set label index of n_file to colour end repeat end tell
Replace the number in the fourth line with one of the following: 0 = No colour 1 = Orange 2 = Red 3 = Yellow 4 = Blue 5 = Purple 6 = Green 7 = Grey
5. Enable/Disable Growl Notifications
This page over at Mac OS X Hints has a great script for toggling Growl notifications on and off. Really useful for turning them off just before a presentation.
6. Go to Login Window
Quickly switch over to the login window without actually logging out. Works similarly to a "lock screen" shortcut.
do shell script "'/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession' -suspend"
7. Sync with MobileMe
do shell script "/System/Library/PrivateFrameworks/DotMacSyncManager.framework/Versions/A/Resources/dotmacsyncclient sync"
8. Paste as plain text
This script just strips the formatting out of text in the clipboard. So you use Command-C to copy a load of formatted text, then Control-C (or whatever) to strip formatting, then Command-V to finally paste it.
do shell script "pbpaste | pbcopy"
9. Create a short URL
This script creates a short URL of the current page in Safari and copies it to the clipboard. Then all you need to do is paste into where you want it.
tell application "Safari" set bigURL to the URL in document 1 end tell set tinyURL to (do shell script "curl --url \"http://metamark.net/api/rest/simple?long_url=" & bigURL & "\" ") set the clipboard to tinyURL
10. The built in scripts
Most of the scripts that come with Mac OS X are pretty useless, but some are quite fun. They are all located in Macintosh HD/Library/Scripts. Here are the ones to look out for:
- “Show/hide all” in Finder Scripts
- “Create New Message” in Mail Scripts
- “New Applications Window” in Navigation Scripts
- “Convert to PDF” in the Printing Scripts
- “Download Weather Map” in the URLs folder