Bill Lovett

A Spotlight Alternative With Perl

Posted on August 12th, 2007

I like to use the built in features of OS X rather than resort to third party applications. It's rare to find an application that's hands-down better at whatever it does compared to what you get from Apple. More often you find something that's a little better, or just slightly different. Until recently, this was my attitude toward Spotlight. It wasn't as fast as I might like but it more or less got the job done.

I mainly used Spotlight for quick access to applications. Of all the things that Spotlight can index, from Address Book contacts to Fonts to Keynote Presentations, Applications were were the only thing I genuinely needed quick access to. Everything else could be reached through other means when needed. Most of the time it wasn't. Yet even after scaling back Spotlight's purview, it still wasn't fast or precise enough. Perl to the rescue!

My Spotlight replacement, at least for launching applications, is a Perl script that I run from the Terminal. It takes advantage of the fact that applications on OS X live in the Applications folder, and are special folders that end in ".app". When run with --crawl as its first argument, launch.pl will scan the Applications folder recursively and build up a list of all the applications it finds. This list will be written to a hidden text file in your home directory, one application per line.

Once this cache file has been created, run the script again and provide an application as the first argument. The script will grep the cache file, and then launch the desired application via the open -a command. If there are multiple matches in the cache file, it'll prompt you to pick one. For extra convenience, you can use a Bash function like this to shorten the script name to a single letter:

function l() {
    ~/bin/launch.pl ${*}
}

The end result is that when I want to launch Firefox, I type l fox into a Terminal window and Presto! Firefox launches. I can open Safari with l saf or l safari. There's no delay as with spotlight, because grepping the cache file is very fast. There's also no background service left running all the time. The cache file only needs to be rebuilt when a new application is added to the Applications folder.

Back to the index of all blog entries