How can I make spotlight ignore certain file types and directories?

Solution 1:

Short answer: yes.

Go to your System Preferences, then Spotlight:

Spotlight Preference Pane

You can disable and/or reorder the items in this list. By dragging Applications to the top, "Saf" will match Safari first (because it's an App, regardless of it's location).

If, on the other hand, there's a Folder(s) or Drive(s) that you want to explicitly exclude from Spotlight until you change your mind, turn onto the Privacy Tab (on top of that panel) and click the (+) button to browse for a folder.

Spotlight Privacy Pane

This window also accepts Drag and Drop of Folders or Drives (Volumes). In my Sshot, you can see that I exclude Clone (my weekly clone drive) from Spotlight so when I search for something I don't come up with duplicated results (one from the main drive and one from the backup).

I also have added a Public Folder where a lot of ppl drops stuff and I don't care about it nor I want it in my search results.

If you want to restore it, you can always remove it from this list (and give spotlight time to re-index it).

You can't (as far as I know) exclude by File type.

Note: in order to drag a "drive" just go go the finder, click on your Mac OS Volume and then press ↑ (the up arrow) to go back to the "root", you will see your volumes there (among other things). Drag it and drop it onto this Privacy tab and voilá.

Solution 2:

There is a way to exclude folders: add a .no_index extension to the file or folder name.

But my favourite one is adding a .metadata_never_index file to a folder. Use the following command:

$ cd DIRECTORY
$ touch .metadata_never_index

Solution 3:

Not being able to exclude by file type is really annoying. This source claims that if you append .noindex at the end of the filename that file is excluded by safari indexing. I have not been able to verify this trick, but could be interesting for others to try it out.