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.


5 Answers 5


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.

  • 1
    @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, 2019 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, 2019 at 17:04
  • Thanks. Hopefully these comments document it well enough.
    – Ashley
    Nov 18, 2019 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) Jul 31, 2020 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, 2020 at 19:54

The VolumeConfiguration.plist has moved

It now resides in /System/Volumes/Data/.Spotlight-V100/VolumeConfiguration.plist.

You can easily edit it using /uar/libexec/PlistBuddy


sudo /usr/libexec/PlistBuddy -c "Print :Exclusions" /System/Volumes/Data/.Spotlight-V100/VolumeConfiguration.plist


The zero indicates the element in the array or in this case the beginning of the array

sudo /usr/libexec/PlistBuddy -c "Add :Exclusions:0 string '/path/to/folder'" /System/Volumes/Data/.Spotlight-V100/VolumeConfiguration.plist


The zero indicates the the first item in the array

sudo /usr/libexec/PlistBuddy -c "Delete :Exclusions:0 string" /System/Volumes/Data/.Spotlight-V100/VolumeConfiguration.plist

Restart the daemon

Easiest solution to get the change to take effect is reboot, but you can also tell Launchd to restart the mdworkers

sudo launchctl stop com.apple.metadata.mds
sudo launchctl start com.apple.metadata.mds


If however, you decide you want to disable spotlight indexing on the whole volume, for example if the machine is a headless build machine, you could just use mdutil.

mdutil -i off /
  • 1
    While the commands you posted do as stated, they do not change the current state of Spotlight indexing, nor does the added entries show in System Preferences > Spotlight > Privacy. So unless you have a way to also make the changes go into effect, then not sure of the value of this answer. Sep 28, 2021 at 22:06
  • You'll need to restart of course or restart the daemon Jan 10, 2022 at 10:22
  • 1
    If you have an error running these commands (e.g., Error Reading File: ...), you probably need to give your terminal program full-disk access (under System Preferences > Security & Privacy > Full Disk Access). Jun 12, 2022 at 19:04
  • @user3439894 if you want your changes to appear under Spotlight > Privacy, you will need to do so manually. Maybe there is an MDM way? However, the goal here is to disable searching for a given directory, so in that I believe this works. Jun 26, 2022 at 9:49

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

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.

  • 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?
    – d0g
    Mar 29, 2013 at 7:03
  • I am not so sure, but the defaults are -rwx-------? Mar 29, 2013 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!? Mar 29, 2013 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. Nov 13, 2017 at 4:51
  • For me it just says operation not permitted. I'm on mojave.
    – Jonathan
    Jun 8, 2020 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.

  • 1
    The question was about how to do this programmatically. Obviously it can be done via GUI.
    – d0g
    Apr 19, 2013 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, 2015 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, 2015 at 17:05

You must log in to answer this question.

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