MacOS – How to blacklist filetypes from Spotlight search results

macosspotlight

Spotlight has a quirk that I want to fix, if possible. When I search for certain keywords, such as categories in System Preferences, Spotlight will place a document as the "Top Hit" in the search results, even though System Preferences have a higher priority over Documents in Spotlight's preferences. I want to be able to blacklist certain filetypes while preserving the "Documents" category.

For example, typing "sharing" will return the top hit as "sharing.qml" from the Qt5.1.1 directory, followed by Sharing in System Preferences. I can't then immediately press enter to open "Sharing" without first pressing the down arrow.

Sharing with incorrect ordering of results


What I am able to do to fix this individual issue is blacklist the Qt5.1.1 examples directory.

Second incorrect result

You can see that it returns "sharing.html" from the gtk-doc directory now. So I blacklist that directory as well.

Finally

Now I am able to search for "Sharing" with no issues. However, there are other search results that exhibit similar behavior, such as when typing "mouse". It is too tedious to block each directory that I find.

I don't want a rkt file


Settings for Spotlight


I want to be able to blacklist individual filetypes from Spotlight. I have set "System Preferences" to have a higher priority than "Documents" in Spotlight as well. Nothing seems to affect the "Top Hit" other than individually blacklisting each directory that holds a file that I don't want to see.

Is there a better way?

Best Answer

  1. Find the importer used to import that type of file.

    mdimport -d 4 -n /path/to/file 2>&1 | grep Imported

    mdimport -d 4 -n ~/Desktop/avatar.png 2>&1 | grep Imported
    2014-06-19 11:17:04.929 mdimport[30911:412893] Imported '/Users/grgarside/Desktop/avatar.png' of type 'public.png' with plugIn /System/Library/Spotlight/Image.mdimporter.
    

    The above example shows the type as public.png in the Image.mdimporter importer.

  2. Open /path/to/importer/Contents/Info.plist in an editor.

  3. Find the item of the same type as the type of the file that you found from the above command and delete it.

  4. Reimport the importer.

    mdimport -r /path/to/importer

    mdimport -r /System/Library/Spotlight/Image.mdimporter
    

Don't forget to have backups and note this procedure may be overridden on OS X updates.