macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Hit-and-Run: Launching AppleScripts with Keyboard Shortcuts
Pages: 1, 2, 3, 4, 5

Double-click on the newly created trigger. This will bring up the options drawer, in which you can define the actual keyboard shortcut in the Hot Key field (Figure 9).

figure 9
Figure 9. Defining the key to trigger our newly created task.

As it is now, hitting Control-M will launch our "Pause iTunes" AppleScript, regardless of which application is currently active. If you want, however, you can also limit the scope for this keyboard shortcut by clicking on the Scope tab in the options drawer, choosing the appropriate scope from the pop-up menu, and if needed, typing a list of applications in the text field (Figure 10).

figure 10
Figure 10. Limiting the scope of keyboard triggers.

Limiting the scope of the keyboard shortcut is not the only advantage Quicksilver has over FastScripts. Thanks to a special kind of object called Proxies, Quicksilver can access the Current Application, Current iTunes Playlist, Current Selection, etc. (To enable Proxies, check the Enable Advanced Features option in Quicksilver's Preferences → Application preferences.)

Beyond script launching

The Current Selection can mean a lot of things, like the currently selected text in a text editor, the currently selected tracks in iTunes, or—and this is what we will need—the currently selected files in the Finder. By using the Current Selection proxy, we can tell an AppleScript droplet to launch with the files selected in the Finder, just as if we had used the mouse to drag and drop the files onto the droplet's icon.

Assume we have an AppleScript droplet called Create Image Icon that creates image icons for any image files you drop onto it. In Quicksilver, you can create a keyboard shortcut that will run this script on the current Finder selection by creating a new keyboard trigger for a command that has "Current Selection" as the object, "Open with…" as the action, and "Create Image Icon," the AppleScript, as the target.

Now, whenever you select some files in the Finder and hit the keyboard shortcut you have assigned to this command, the AppleScript will run on the Finder selection. No need to move your hand to the mouse to drag any files onto the droplet. Also, you can neatly store the droplet somewhere other than your desktop, because you don't have to have it within "drag-n-dropping distance."

Caveat: Unfortunately, as of this writing, this process does not work as it should: when you select more than one file in the Finder and launch the AppleScript droplet with this selection via Quicksilver, only the first file in the selection is handled by the AppleScript. It sure would be nice if this was fixed in an upcoming version of Quicksilver. Until then, you can at least use this technique for one file at a time.

Automator workflows, too!

Since, unlike OS X Script Menu and FastScripts, Quicksilver's search for script files is not limited to specific folders, we might as well assign keyboard shortcuts to Automator workflows, too. All we have to do for this is tell Quicksilver to include the Automator files in its Catalog. Here's how.

Open Quicksilver's Catalog preferences, click on the plus sign at the bottom and choose "File & Folder Scanner" from the pop-up menu. Navigate to:

<your home folder>/Library/Workflows

This is where Automator stores its workflows. After adding this folder to the list, Quicksilver will switch to the Custom section. Select the "Workflows" item and click on the "I" information icon to show its options. Select "Folder Contents" from the "Include Contents" menu and, since Automator may store some of your workflows inside application-specific subfolders, choose a (scanning) Depth of 3, so that Quicksilver will "dive" into the subfolders to find all the workflows. Once that's done, you can add a keyboard shortcut to Automator workflows just as you did for the AppleScript files. (See Figure 11.)

figure 11
Figure 11. After adding the Automator folder to its Catalog of objects, Quicksilver lets you assign keyboard shortcuts to workflows, too.

Diving into liquid metal

If you haven't been using Quicksilver yet, you can download the software for free from the Blacktree website.

Quicksilver is a very powerful and flexible tool, and its depth and breadth can be overwhelming. To get started, therefore, you should check out the tutorials found in this list on the Blacktree website. My favorite entry-level tutorials on Quicksilver are those by Lifehacker's Adam Pash: Part 1, Part 2, Part 3.

Which Approach Is Best for You?

There you have it: three options for assigning keyboard shortcuts to your AppleScript and even Automator files. Which of these is best for you?

With the built-in Keyboard Shortcuts system preferences, you can already assign useful shortcuts to application-specific AppleScripts. Although you have to be careful to not make typing mistakes while entering the menu item's name, and despite the lack of support for global shortcuts, this approach may be fully sufficient if you only need to "keyboardize" a few scripts. And it saves you the potential hassle of installing additional software on your Mac.

If you do wish to use global shortcuts, however, installing another piece of software is required. With FastScripts, you not only get support for global shortcuts. The software will also present you with the most user-friendly and most Mac-like way of managing keyboard shortcuts yet — as long as you're using plain AppleScript files in their standard folder locations.

Quicksilver does it all: launch Automator workflows and AppleScripts, send a file selection to be run on an AppleScript droplet, and even finely adjust the scope of any keyboard shortcuts you create. However, using Quicksilver comes at a price: the learning curve is steep and the application is also known for some instabilities. Then again, once you have grokked its usage philosophy and realize what you can generally do with it, Quicksilver may very well give you an overall productivity boost for your daily computing tasks that borders on spectacular.

Jochen Wolters is a telco engineer who enjoys sharing his passion for technology by writing about it. His favorite topics include the Apple Macintosh, user interface design, and just about any kind of creative software.


Return to Mac DevCenter.