MacOS – How to create a Saved Search that excludes a specific folder from the results

finderfoldersmacossearchspotlight

I'm trying to set up a Saved Search of my Mac that will exclude files in a folder called 'XYZ' from the search results. The reason is because I'm getting a ton of false positives from that folder that are difficult to sort through.

Just to be clear, I know you can add folders to a "Privacy" list in the Spotlight preferences, but I don't want to add this folder to that list –because I don't want to exclude it from all future searches, just this specific saved search. Any idea how something like this could be done?

Best Answer

I looked at some of the saved search files in Finder's application bundle, and for example /System/Library/CoreServices/Finder.app/Contents/Resources/MyLibraries/myDocuments.cannedSearch/search.savedSearch used a format like this for excluding directories:

<key>FXScopeArrayOfPaths</key>
<array>
  <string>~/</string>
  <string>-Library</string>
  <string>-Music/iTunes</string>
  <string>-Documents/Steam Content</string>
  <string>~/Library/Mobile Documents/</string>
  <string>-com~apple~Keynote</string>
  <string>-com~apple~Pages</string>
  <string>-com~apple~Numbers</string>
</array>

So you can exclude subfolders by adding strings that start with a minus character after a full path. Something like -~/Library doesn't seem to work.

You can edit savedSearch files by dropping them on a text editor. RawQueryDict:SearchScopes and FXScope:FXScopeArrayOfPaths seem to list the same paths by default, but just editing the second one appeared to exclude folders at least in Finder.