16

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.

16

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.

2

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'

do:

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

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? – 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
-3

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. – 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 .