The Arctic Mac

Tweak Spotlight Behavior

Introduction

This article arises because of my long-standing frustration with Spotlight's lack of ability to just do what I want it to do. Namely, it never seems to be able to find the file I'm looking for (though I admit, I'm often looking for weird files), and it tries to set my MacBook on fire when I do certain things like make a copy of my home directory, etc, etc. As an example of the first one, last week, my mom was working in Microsoft Word, and it crashed. When she reopened it, it pulled up the autosave file, but promptly crashed again, and when she relaunched the second time, the autosave file didn't come up. Now you would think that Spotlight, indexer of all things, would know where to find the directory full of MS Word autosave files. Wrong. It took me about the same time to locate the directory (in, no surprises here, a fairly standard location) as it took spotlight to do the search, and I actually found what we were looking for.

So, you say, why not just disable Spotlight altogether? Well, because of Mail. Most of my files I keep organized well enough that I know exactly where to find a particular file. But in Mail, I have only a few mailboxes, each of which has hundreds of messages in it, so it quickly becomes much harder to find what I'm looking for. But Mail has a pretty good search function, so it's okay. Except that doing a search by anything other than To, From, or Subject requires there to be a Spotlight index of your mail files.

The problem is that I want Spotlight to index only one or two key folders on my disk and nothing else. But the Spotlight system prefs are setup to do just the opposite: index everything but one or two folders. So...

VolumeConfig.plist

There's a file located at /.Spotlight-V100/Store-V1/VolumeConfig.plist which contains some settings for Spotlight on your main disk. Specifically, it contains some index roots, and the indexing policy for each of them. What we're going to do is change existing index from being rooted at the root of the hard drive to being rooted in ~/Library/Mail. Just for the record, VolumeConfig.plist looks something like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>26FE3A13-1842-45B6-8D80-2AA70D76CA06</key>
<dict>
<key>partialPath</key>
<string></string>
<key>policySearch</key>
<integer>1</integer>
</dict>
</dict>
</plist>

Instructions

Open a terminal window. Do sudo mdutil -i off / to disable indexing on your HD.

Then edit (you'll need your editor to have root permissions - I used sudo vi) the VolumeConfig.plist file, giving a value for partialPath (goes in between the string tags), and changing the policySearch value to 3. For example, I set partialPath to Users/myusername/Library/Mail. Note the lack of a leading slash. You can also if you want copy the whole construct (the key for that UUID, and the associated dictionary), and add a second index. I went ahead and added a second index for my Documents directory, which is more or less immune from the problems of lots of file activity, and will be nice to have a spotlight index for. Note that if you do this, you should do uuidgen in the terminal to get a new UUID as the key.

Once you're done editing VolumeConfig.plist, go back to the Terminal and do a sudo launchctl stop com.apple.metadata.mds to restart the Spotlight daemon. In not too long, you'll notice the little dot that indicates indexing come on in the Spotlight menu item, and it'll index your new roots.

For bonus points, you can now control your new indexes with the mdutil command, for example:
mdutil -sv ~/Library/Mail

Contact The ArcticMac