Programatically Adding Spotlight Exclusions
Spotlight has two types of exclusions: Volumes and Directories I’m executing everything as root here, as I assume these commands will usually be executed by some management software that has Full Disk Access and Root Access. This post is Catalina specific, since the VolumeConfiguration.plist file is in a different location on previous macOS releases. This is due to the movement of / to /System/Volumes/Data Volumes can be added and removed as exclusions from Spotlight (while not appearing in System Preferences) with a simple mdutil -i off "VolumeDirectory" Directories however are not so simple. If we try the same thing with a directory, we get the error MBP:~ dan.c$ mdutil -i off "/Users/dan.c/Desktop" /System/Volumes/Data/Users/dan.c/Desktop: Error: invalid operation. Error: unknown indexing state. The solution is to directly edit /System/Volumes/Data/.Spotlight-V100/VolumeConfiguration.plist Since defaults doesn’t allow us to read arbitrary plist f