A Replacement for Spotlight

Spotlight has a glut of nice features, but it still doesn’t satisfy me. I have nearly 2 million files on my hard drive. Depending on what I’m working on (and my caffeine-to-blood ratio), hundreds of files may be updated every minute. Then Spotlight tries to index the drive at inopportune moments, then Ableton Live can’t access files because the drive is busy, and the music grinds to a halt, and …. well, I had to take Spotlight behind the shed, and put it down.

There are many ways to disable Spotlight. I don’t remember which combination worked for me, but the end result is that mdutil doesn’t run on this machine anymore, and my menu bar is devoid of a Spotlight icon. (Also I disabled Quick Look, since its indexing also caused problems.)

But I still want to search my files. My solution was to create an automated job that runs once a day, and saves the path of every file into a big text document. Then I created a little command-line alias called search, which prints any file paths that match a search term. Here’s how to do it:

First things first… We need a script that will traverse the file system, and save the path of every file into a massive text document. This is pretty easy, the find utility can do the heavy lifting. Here’s the script I wrote:

rm /Users/chaz/dev/search/tree.txt
find / > /Users/chaz/dev/search/tree.txt

I saved this script as /Users/chaz/dev/search/build_tree.sh . Make sure it’s executable, then run it:

$ chmod a+x build_tree.sh
$ ./build_tree.sh

The first time through, the rm command will complain that it has no tree.txt to delete, but that’s okay. find will throw some other warnings at you: it can’t traverse every directory because it doesn’t have permission. Again, that’s okay — I probably won’t be hunting for files in such places.

Grab a beverage, this process takes a few minutes. When it’s done, you’ll have a (rather large) tree.txt file in the directory. How large, exactly?

$ wc tree.txt
1719365 5761267 196118611 tree.txt

1,719,365 lines, so I just indexed 1,719,365 files. Awesome.

It would be nice if the indexing ran automatically, preferably when I’m asleep. Since cron is being phased out of OS X Leopard, we’ll use launchd instead. I created this file, called rebuild_search_tree.plist:





Save this into ~/Library/LaunchAgents . You may have to create that directory, and there’s an added wrinkle: for both the LaunchAgents directory and the .plist file, the owner has to be root.

$ sudo chown -R root ~/Library/LaunchAgents

Register this script with launchctl:

$ sudo launchctl load -w ~/Library/LaunchAgents/rebuild_search_tree.plist

Now this launch agent will run automatically at 6:15 every morning.

Finally, we need a command-line tool to search the tree. I added this line to my .profile:

function search() { clear; cat /Users/chaz/dev/search/tree.txt | grep "$@" | more; }

And here’s how you use it:

$ search test
/Applications/Adobe Photoshop CS3/MATLAB/tests/teststats.m
/Applications/Audacity folder/nyquist/test.lsp
/Applications/iTunes.app/Contents/Resources/da.lproj/iTunes Help/gfx/gfx_test.gif

For each file that matches your query, it displays the full path of the file. This could be made fancier, but for now this is all I need!

2 thoughts on “A Replacement for Spotlight

Leave a Reply

Your email address will not be published.