How I use Quicksilver II: Scripts

Quicksilver is the first program any self-respecting Mac user should install on their box. Instead of giving a general overview of its features (there are already plenty of those), I’m going to prove Quicksilver’s worth by going over exactly how I use it.

This is part two, on scripts.

As I mentioned in the first installment of this bit, I’m going to devote this entire post to explaining how I use scripts with QS. I want to go over some general tricks for employing Quicksilver to run Applescripts and commands as well as discuss some useful QS actions, which are just more complicated scripts that accept inputs from the QS interface.

Useful Trigger Options

Most of the scripts I use are simple Applescripts that I have hotkeyed using standard QS triggers with the “run” action. There are two more advanced trigger options that make these sorts of triggers flashier and easier to use. (Noob note: to view options for a trigger, select it and hit the “i” button in the lower right.)

If the “Show Window” option is on, QS will produce a flashy bezel when this trigger is activated. I’m usually not a fan of stupid eye-candy, but visual feedback is essential for many of these scripts because they perform functions that will run in the background.

I noticed early on that the Show Window bezel displays the icon of the script that its trigger executes. This means that you can identify a script by changing its icon to something relevant to its function. If you’re not sure how to do this, go over this Macinstruct article or use the IconGrabber QS plugin (at the risk of creating a hole in the space-time continuum). I will go over some examples of the Show Window bezel in action to illustrate its practicality.

The second trigger option worth noting is the “Delay:” field, which allows you to specify a time (in seconds) that you will need to hold the trigger’s hotkey before it will activate. This feature safeguards against accidental keypresses and gives the Display Window bezels more screen time.

iTunes Scripts

Quicksilver lets me search through my entire 41 GB music library without ever having to bring iTunes forward. I can play, pause, skip tracks, and shuffle artists, songs, and albums through QS’s interface. I use scripts to accomplish the remaining iTunes tasks I perform with any regularity, so that I can manage my music library almost exclusively through Quicksilver. A key element of this system is Growl, which displays track information in temporary on-screen notifications.

For Rating Tracks

I use command-option-1 through command-option-5 to set the currently playing song’s rating to a corresponding number of stars. The applescripts to perform this task are included in the iTunes Module plugin:

~/Library/Application Support/Quicksilver/Plugins/iTunes Module.qsplugin/Contents/Resources/Scripts/

I mention the scripts’ location because this is one instance where the Show Display bezel is absolutely necessary. I navigated to the above directory and slapped each of my five rating scripts with an icon that, when it appears in the Show Display bezel, will confirm I’ve just rated the currently playing song a certain number of stars.

For Displaying Track Information

Because Growl’s song information notification only lingers on my screen for a few seconds and I shuffle often, I’m sometimes left wondering exactly what I am listening to. Luckily, Growl is fully Applescriptable, so I can use a QS trigger to force it to display the currently playing track’s information again. Specifically, I use command-option-? to execute this script (credit to RavenDuck at the Blacktree Forum).

For Adjusting Volume

Using my function keys for application launching is convenient, but it left me wanting for an easy way to change the system volume. Since OS X doesn’t allow hardware functions to be mapped anywhere outside of F1-F12, I turned to these two scripts. I have them hotkeyed to command-. and command-/, with Display Window on. You’ll notice that the scripts in that archive already have icons to reflect their functions.

For Tagging Tracks

The last bit of scriptery I use to control music playback is the TuneTag action suite by Chris Brown. The Tag and TagSelected actions allow me to tag my iTunes tracks, and the PlayTag action plays back tracks with a specified tag. All of these actions are accessible entirely from the Quicksilver interface, though the TagSelected action is designed for batch tagging while songs are selected in iTunes.

TuneTag’s tags are just strings in the Comment field preceded by an asterisk, but they offer unlimited control over the organization of my music library. I can do cool things like tag loud, aggressive music with “angry” so I can play it immediately after I’ve been in my Windows partition for a while.

Shell Scripts

I use shell scripts to take care of certain hardware functions. Though Quicksilver can handle shell scripts directly using the Terminal Module plugin, I prefer to pipe the scripts through Applescript with the do shell script command, because then I can assign them icons for use in Display Window bezels.

For Booting into Windows

I explained this script in a more detailed Macinstruct article, which is a generally good reference if you are interested in more specific information about how to set up scripts for activation via Quicksilver. In short, I use control-B to trigger this script after a two second delay. The script first sets my startup volume to my Windows partition (named “XP” — you must replace this string with your partition’s name if you want the script to work properly) and then restarts my computer.

It’s a true luxury not to have to wait around to hold down the option key during boot to specify my Windows partition, and when I power down Windows after using this script I will boot back into OS X (i.e. the startup volume change is not permanent).

For Forcing a Time Machine Backup

Time Machine is an optimal backup solution because it requires no user input, but instead runs automatically in the background on a regular schedule. For someone who leaves their Time Machine-stamped external drive plugged in all the time, the regular, scheduled backups work like a charm.

However, I rarely power on my external, and when I do I’d like to be able to tell Time Machine to interrupt its usual schedule and back up my data immediately. Logan Rockmore uncovered a shell script to do exactly this, and it was short work for me to stick it in an Applescript, apply Time Machine’s icon, and create a QS trigger: when I hold command-ctrl-T for two seconds, Time Machine will spring to life.

For Toggling AirPort Power

I turn my AirPort on and off frequently, depending on my power source and access to ethernet cable. My general aversion to using the mouse for common actions sent me looking for a way to toggle my wireless card’s power with a hotkey. What I turned up was this script, which uses GUI scripting to identify the AirPort menubar item and select its topmost option.

I have no idea where I found the script originally and Google doesn’t have any answers, so I can’t credit it properly. Works like a charm, though.

For Stripping Text Formatting

Pasting from a website into a rich text document used to drive me nuts. The copied text would drag its hideous font and wacky formatting into whatever I was working on. I ran across a command that strips whatever text is on the clipboard down to plain text by re-copying it:

pbpaste | pbcopy

I skipped the AppleScript and Display Window bezel for this one, opting simply to create a “Run Command in Shell” trigger with pbpaste | pbcopy as the object. I mapped the trigger to control-u, and have already used it to save plenty of time and frustration.

For Swapping Preferences

There exists a fairly popular piece of shareware called RooSwitch that allows users to shuffle preference files around so they can create multiple user “profiles” for any single application. Though I’m certain RooSwitch is best at what it does, you can achieve its basic functionality by using scripts and Quicksilver, and you can do it for free.

The reason I know this is because USBOverdrive’s application-specific settings don’t work properly in Leopard. I need USBOverdrive to map my mouse buttons to crouch, use medkit, re-arm, and walk so I can properly dominate in the excellent Quake3-based FPS Tremulous. These functions aren’t so useful while I’m cruising around in OS X, so I wrote an Applescript to swap out my global USBOverdrive settings for my Tremulous-specific settings:

do shell script "mv ~/Library/Preferences/com.usboverdrive.mouse.prefs ~/Library/Preferences/com.usboverdrive.1/"
do shell script "mv ~/Library/Preferences/com.usboverdrive.2/com.usboverdrive.mouse.prefs ~/Library/Preferences/"
do shell script "mv ~/Library/Preferences/com.usboverdrive.1/com.usboverdrive.mouse.prefs ~/Library/Preferences/com.usboverdrive.2/"
tell application "USB Overdrive X" to activate
tell application "USB Overdrive X" to quit

The script is probably somewhat clumsy because I’m a unix noob, but it gets the job done and you can easily adapt it to any other application’s preferences. It will switch the .plist file in my ~/Library/Preferences folder with a second .plist file in a dummy folder, effectively toggling between global settings and Tremulous settings. I hotkeyed the script to command-option-F9, because command-1-3-3-7 isn’t possible.

Web Scripts

These last few scripts make browsing and interacting with web-based services convenient. I plan to get into a little more detail on how Quicksilver can help you access remote data when I go over plugins in the next, third part of this series.

For Tweeting

I love Twitter. Now that Twitterriffic is adware, Coda Hale’s Tweet action for Quicksilver is undoubtedly the slickest way to post updates to Twitter. It will accept text input directly from the QS interface and post it to my Twitter feed.

The Tweet action I use is a modification by Joe Carroll that provides length-checking before posting (Twitter will reject Tweets over 140 characters) and Growl notification upon posting. These improvements make the Tweet action’s featureset par with that of Twitter’s web interface, meaning I don’t have to sacrifice functionality for convenience.

Update: Commenter Alex noticed that the script I’ve mirrored above doesn’t work if the tweet’s first character is “@”. His improved version fixes the error, and I’m using it now. Thanks Alex!

For Shortening URLs

Complex websites can spit out obnoxiously long URLs that are a chore to email or enter in text fields. URL-shortening services like the excellent, bare-bones Metamark use redirection to change obnoxious, long URLs to cute, concise ones like http://xrl.us/bbz66.

Macworld honcho Jason Snell whipped together a handy Applescript that retrieves the URL of Safari’s frontmost page, sends it to Metamark for shortening, and places the new, cute, URL on the clipboard. I have his script hotkeyed to control-I, and use it most often when I am posting a link to Twitter (with the Tweet action, of course!).

For Navigating Page-Based Sites

Daniel Jalkut of Red Sweater Software has written quite a few useful Applescripts. Amongst them is Safari Next Page, which examines the URL of Safari’s frontmost page to determine if it is one in a series of pages (usually URLs of paged articles and content will have some indicator like page=2). If Safari Next Page recognizes the URL’s format, it will load the next page in the series.

This script is quite useful for navigating websites that enjoy compromising their usability by splitting articles into multiple pages, and I have it mapped to command-right arrow while Safari is the frontmost application.

8 Responses to “How I use Quicksilver II: Scripts”

Emily Says: November 30th, 2007 at 10:39 am

Great writeup! Thanks for the ideas.

immensewok Says: December 30th, 2007 at 8:53 am

The script for Growl track notifications is useful and I picked up a few things by reading through it but there’s a much easier way to do it.

tell application “GrowlTunes” to show current track

Alex Says: January 28th, 2008 at 5:10 am

Joe,

Great set of articles, much appreciated.

One thing, I’d like to grab your modified Tweet script, but the link is dead - blacktree.cocoaforge doesn’t seem to be up.

Is there any place I could grab this from?

Cheers

jwdunn Says: January 29th, 2008 at 12:14 am

Alex - I uploaded a copy of the script here:

http://jwdunn.com/file/tweet.zip

The link in the article now points to that file. Credit goes to Joe Carroll for the script, as mentioned above.

Glad you enjoyed the articles!

Alex Says: January 30th, 2008 at 1:06 am

Joe,

Thanks for the upload, once again, much appreciated.

When working with the script, I noticed that it errors out when starting a tweet with ‘@name’ or with any ‘@’ at all in it for that matter.

I’ve made an adjustment to the ‘do shell script’ command and replaced -F with –data-binary. That seemed to fix the problem.

I also spiced up the Growl notification messages. Hopefully, this little fix is a way of thanking you for these great posts.

The adjusted Tweet script can be found here:
http://www.culturevation.com/drop/Tweet_At.zip

Cheers.

TwistedLogic Says: April 27th, 2008 at 3:10 pm

I don’t understand how to do the notification of current track information. Is someone willing to walk me through how to do that? I’ve spent a couple hours now trying to figure this out and so far to no avail. It’s frustrating because otherwise I’m happy with the GrowlTunes/Growl combo. I just need to be able to pull up current track info.

jwdunn Says: April 27th, 2008 at 9:42 pm

TwistedLogic, specifically what is your problem? To use the script I posted here, simply place it somewhere on your HD and make a QS trigger that will perform the Run… action on it. As long as you have Growl open, the script should work (GrowlTunes is not necessary for this script, it talks directly to Growl and tells it to display track information).

You might try opening the script in Script Editor and check to be sure none of the filepaths it lists are incorrect for your computer - sometimes if you have an application or file in an unorthodox place a script will miss it (but in that case you’d see an error message I think).

Michael Says: May 27th, 2008 at 4:38 am

Hi I’ve been searching for the last few hours for the command to toggle shuffle for QS. (And yes, I tried that). Specifically, ‘tell app ‘iTunes’ to something-or-other shuffle..’

Do you have any ideas that might help? Thanks.

Leave a Reply