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):
$ sudo cp /System/Library/CoreServices/Search.bundle/Contents/\
Resources/MDSimpleGrouping.plist /System/Library/CoreServices/\
Search.bundle/Contents/Resources/MDSimpleGrouping.plist.backup
$ sudo cp /System/Library/CoreServices/Search.bundle/Contents/\
Resources/English.lproj/MDSimpleGrouping.strings /System/Library/\
CoreServices/Search.bundle/Contents/Resources/English.lproj/\
MDSimpleGrouping.strings.backup
$ sudo cp /System/Library/Frameworks/CoreServices.framework/\
Versions/A/Frameworks/Metadata.framework/Versions/A/Resources/\
MDPredicate.plist /System/Library/Frameworks/CoreServices.\
framework/Versions/A/Frameworks/Metadata.framework/Versions/A/\
Resources/MDPredicate.plist.backup
$ sudo cp /System/Library/Frameworks/CoreServices.framework/\
Versions/A/Frameworks/Metadata.framework/Versions/A/Resources/\
English.lproj/MDPredicateKeywords.plist /System/Library/\
Frameworks/CoreServices.framework/Versions/A/Frameworks/\
Metadata.framework/Versions/A/Resources/English.lproj/\
MDPredicateKeywords.plist.backup
$ sudo cp /System/Library/PreferencePanes/Spotlight.prefPane/\
Contents/Resources/English.lproj/Localizable.strings /System/\
Library/PreferencePanes/Spotlight.prefPane/Contents/Resources\
/English.lproj/Localizable.strings.backup
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):
to this:"com.apple.safari.bookmark" = "BOOKMARKS";
Save and close the file. Then open /System -> Library -> CoreServices -> Search.bundle -> Contents -> Resources -> English.lproj -> MDSimpleGrouping.strings, and replace this line:"com.microsoft.word.doc" = "BOOKMARKS";
with something more representative:"BOOKMARKS" = "Bookmarks";
Save and quit your editor. Now documents of type com.microsoft.word.doc will fall under the category with dummy name BOOKMARKS, but will be labeled as Word documents."BOOKMARKS" = "Word Documents"; - Now we want to allow keyword searches for our new category. Open -> System -> Library -> Frameworks -> CoreServices.framework -> Versions -> A -> Frameworks -> Metadata.framework -> Versions -> A -> Resources -> MDPredicate.plist, and replace the following line:
with:BOOKMARKS = "kMDItemContentTypeTree = com.apple.safari.bookmark";
Save and close the file. Then open /System -> Library -> Frameworks -> CoreServices.framework -> Versions -> A -> Frameworks -> Metadata.framework -> Versions -> A -> Resources -> English.lproj -> MDPredicateKeywords.plist and change:BOOKMARKS = "kMDItemContentTypeTree = com.microsoft.word.doc";
to something like:<key>BOOKMARKS_STRINGS_LOCALIZED</key><br> <array><br> <string>kind:bookmark</string><br> <string>kind:bookmarks</string><br> </array>
(or choose your own keywords). Save and quit.<key>BOOKMARKS_STRINGS_LOCALIZED</key><br> <array><br> <string>kind:word</string><br> <string>kind:word document</string><br> </array> - 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:
to this:"CATEGORY_BOOKMARKS" = "Bookmarks";
Save and quit."CATEGORY_BOOKMARKS" = "Word Documents"; - Now to make these changes take effect, type this command into Terminal, then press Enter:
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).killall SystemUIServer
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.
•
[16,947 views]

