I've been trying to make Spotlight more useful to me, and one of the first things that came to mind was changing the categories of files that it searches. I rarely if ever search for Bookmarks, Fonts, Mail Messages, Contacts, System Preferences, or Events and To Do Items, and was wondering if I could replace them with something more convenient.

Anyway, it turns out that this is possible, although not as completely as I would have hoped. You can quite straightforwardly change an existing category to list a different type of file. Note that this does not stop Spotlight from showing files in the category you replace, it just makes them show up as normal documents. You can also add a new category. However, if you do this, it will only show up in the results window, not in the list that drops down from the menubar or in System Preferences. Changing an existing category will probably be more useful to most people.

Warning: these methods involve modifying five system files. You may completely stuff up Spotlight, or your entire system, if you do something wrong. Read on for the step-by-step...

[robg adds: I have not tested this one, and it does require editing some relatively deeply-buried system files. However, the concept seems amazingly useful; hopefully Apple adds the ability for self-created categories in 10.5 (or some enterprising coder adds a third-party GUI app for it in 10.4). For this one, though, proceed at your own risk.]

Before changing anything, make sure you back up by running these commands in the Terminal (just copy and paste to a Terminal window):

Once that's done, here's how to tweak Spotlight to match your needs...

Changing an existing category

As an example, we will change the Bookmarks category into a Microsoft Word Documents category. Bookmarks will still be displayed but as ordinary documents, while Word Documents will now have their own category.

First we have to actually change the type of file that is put into the category. In your favourite text editor (I use vi), with administrator privileges, open this file: /System -> Library -> CoreServices -> Search.bundle -> Contents -> Resources -> MDSimpleGrouping.plist. Change the following line (note that some spaces were removed for a narrower display):

Finally, we want to make our new category labeled correctly in the Spotlight preferences panel, so we can change where it appears in the results list. Open /System -> Library -> PreferencePanes -> Spotlight.prefPane -> Contents -> Resources -> English.lproj -> Localizable.strings, and change this line:

"CATEGORY_BOOKMARKS" = "Bookmarks";

to this:

"CATEGORY_BOOKMARKS" = "Word Documents";

Save and quit.

Now to make these changes take effect, type this command into Terminal, then press Enter:

killall SystemUIServer

When the Spotlight icon reappears in the menubar, Word documents should have their own category, and you should be able to find all the Word docs on your computer by typing kind:word. The only minor catch is that the wrong icon is displayed for the new category in the Spotlight prefpane (icon data seems to be stored in /System -> Library -> PreferencePanes -> Spotlight.prefPane -> Contents -> Resources -> icons.data, and can't be easily changed).

Adding a new category

It is also possible to add an entirely new category, but files that fall under it will only show up in the Spotlight results window (default Command-Option-Space). They will not show in the drop-down list from the menubar (unless they are the top hit), and not in the Spotlight preferenes pane, which means they will always appear at the bottom of a search.

To add a new category, follow the instructions for changing a category, but add the given lines to the relevant files instead of altering existing lines (don't worry about changing the prefpane Localizable.strings file: it won't do anything). It doesn't matter where in the strings files the lines are added, but in the plists they must be added in the right place. The easiest way is just to copy one of the existing lines and paste it directly underneath.

Final Comment

You can use this method to change or add (or even remove) any Spotlight category. If you don't want to lose a category, you could change one as descibed above, and then merge the one you replaced into another related category. For example, on my computer, I've combined the Contacts and Events categories into one, and made a category for Word docs. You could also just add new filetypes to existing categories by adding a line in MDSimpleGrouping.plist.

One final note: you may have noticed that two of the plists we encountered here contain the keyword definitions that enable you to type things like date:yesterday or kind:movie into the Spotlight bar (these are the ones with predicate in the name). You can tinker with these files to create other keywords for filetypes or date ranges that you use a lot. You could, for instance, create the kind:word keyword without making a new category specifically for Word documents.

I just tried BSP. It doesn't work at all for me... Then I restarted and my menu items will not load. None of the native OS X menu bar items work (spotlight, airport, volume, etc.). It screwed things up for other user accounts too. I would not recommend using or even trying BSP.

If anyone has any possible methods for me to fix this I would be glad to hear them too.