I have finally got tired with OS X Leopard's Spotlight. It is a great tool to quickly find the documents and programs but it is so annoying when it comes to the external disks! I have a 500Gb USB disk that I use for backups. USB is not so fast but once I connect it, Spotlight starts indexing it, which, obviously, does not make the things faster. In addition to that, it takes a lot of extra space for nothing.

Existing solutions include either disabling Spotlight entirely (I still want it to be active for my primary disk), pretending that the problem does not exist (Apple way ;) ) or buying a commercial tool that disables the Spotlight for a particular drive. Adding the drive to the “Privacy list” does not help, once I disconnect the external drive, it disappears from the list.

I have declared a war against Spotlight. Basically, all I needed was a hook that I could use to run a script once a drive is connected. I would run “mdutil” to disable indexing and that would be all I need.

Apple provides a service called “launchd” that allows to launch something on an event. And, luckily, there is a flag called “StartOnMount” that allows to schedule a command to be executed when a filesystem is mounted.

The rest was easy. Here is an example of the configuration file for launchd that does the trick:

<?xml version="1.0" encoding="UTF-8"?>
  "-//Apple Computer//DTD PLIST 1.0//EN"
<plist version="1.0">

As result, once any filesystem is loaded, the script “/usr/local/bin/stop-spot.sh” will be executed. And the script may look like this:


function shut_spotlight_for_volume() {
    if [ -d "$1" ] ; then
        mdutil -E -i off "$1"

shut_spotlight_for_volume "/Volumes/NO NAME 1"
shut_spotlight_for_volume "/Volumes/MAC_BACKUP"
shut_spotlight_for_volume "/Volumes/MY_VOLUME"

The contents of the script may vary - you may erase the .Spotlight directly of the volume, kill “mds” server etc - whatever you want to do to stop this process from doing the job you do not want to be done :)

The last step is to load this configuration file into launchd. You can do it by using the command like this (assuming that the XML configuration file is saved to /System/Library/LaunchDaemons/org.myhowto.stop.spotlight.plist) :

sudo launchctl load

For more information on the commands involved, read the manual pages for “launchd”, “launchd.plist”, “launchctl” and “mdutil”

blog comments powered by Disqus


10 September 2008