Is there any way to programmatically add a folder to Spotlight's "Privacy" tab? Either through Terminal or Applescript?

Often I want to click on an item in Spotlight results in Finder, and have that item's folder no longer be indexed.

I found that if you

sudo defaults read /Volumes/foo/.Spotlight-V100/VolumeConfiguration.plist Exclusions

you can see an array with all the items excluded.

But if you try to

sudo defaults write  /Volumes/foo/.Spotlight-V100/VolumeConfiguration.plist Exclusions -array-add '/path/to/folder' 

it does NOT get added to the Privacy tab in the Spotlight Preference Panel, nor does it get de-indexed.


According to an answer here, a folder can be excluded from Spotlight indexing (achieving the same effect as adding it to the Privacy tab, although the folder won't actually be listed there) by either

  • adding .noindex to the end of the folder's name, or
  • creating an empty file .metadata_never_index inside the folder (eg with touch folder/.metadata_never_index)

You will need to restart Finder after adding .metadata_never_index, either killall Finder from Terminal or logout from the Apple menu and then log back in. This method doesn't work in Mojave and later.

| improve this answer | |
  • @ankii You've added "This method doesn't work in Mojave and later". Does that apply to the entire answer, or just the final paragraph? – Ashley Nov 18 '19 at 13:55
  • Just the .meta_never_index method. See some discussion here: apple.stackexchange.com/questions/375396/… I am doubtful of High Sierra, but Mojave is surely ignorant of the same. If you want to edit it, put a space before You will need.. and it will fix the ambiguity of which method it applies to. – anki Nov 18 '19 at 17:04
  • Thanks. Hopefully these comments document it well enough. – Ashley Nov 18 '19 at 23:20
  • If the .metadata_never_index doesn't work on Mojave, then how can we disable indexing on a whole volume? (not just a single dir) – Óscar López Jul 31 at 18:27
  • @ÓscarLópez I think that's worthy of an entirely new question - this question is about folders, and my guess is that changing this at the volume level would need quite different solutions. – Ashley Jul 31 at 19:54

You have to stop and start the launchd service called com.apple.metadata.mds. So after:

sudo defaults write /Volumes/foo/.Spotlight-V100/VolumeConfiguration.plist Exclusions -array-add '/path/to/folder'


sudo launchctl stop com.apple.metadata.mds && sudo launchctl start com.apple.metadata.mds
| improve this answer | |

First you have to change the permission settings to add something to the spotlight privacy tab sudo chown -R $USER:$GROUP /.Spotlight-V100/ sudo chmod -R 777 /.Spotlight-V100/

and then

sudo defaults write /.Spotlight-V100/Store-V1/Exclusions Exclusions -array-add should work.

And don't forget to set it back afterwards.

| improve this answer | |
  • 1
    When I did -array-add the folder was added to the plist; it just didn't have any effect. In other words, it showed up with defaults read, but it did NOT show up in the Pref Panel. Do you think this permission mod would make a difference? – Dan Mar 29 '13 at 7:03
  • I am not so sure, but the defaults are -rwx-------? – bluewoodtree Mar 29 '13 at 17:11
  • Sorry I misunderstood, I thought it would not get added at all. I am not so sure, but the defaults are -rwx-------? In this case you may be right and it should not make any difference if you have it changed -rwxrwxrwx with chmod 777. But it is worth a try!? – bluewoodtree Mar 29 '13 at 17:18
  • I believe Store-V1 is only used by older versions of Mac OS X... it is empty on my systems with 10.9 Mavericks and later. You might try modifying the command to use Store-V2 instead. – Jim Grisham Nov 13 '17 at 4:51
  • For me it just says operation not permitted. I'm on mojave. – Jonathan Jun 8 at 14:00

You could also just go to the system prefs pane for Spotlight. There you'll find a privacy tab. Just add the folders and files you don't want to show up in the index. That's it. They've already made it easy so you don't have to use the command line.

And If it's added to the privacy tab you can see what all you have hidden from the index just in case you want to index it it later.

| improve this answer | |
  • 1
    The question was about how to do this programmatically. Obviously it can be done via GUI. – Dan Apr 19 '13 at 17:12
  • 1
    @Ze'ev: A valid point... but next time, since doing it programmatically is so central to the question, you should probably include "programmatically" in the title. – LarsH Jan 23 '15 at 16:35
  • @Ze'ev: your question details disagree with your title. You need to make your title clear and accurate to the question – smci Jul 31 '15 at 17:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .