Testing Spotlight Privacy
I use mdfind
for testing if a method of preventing Spotlight works. I create a folder called spotlight_test
place a file that I know Spotlight can find like dSYMs or an image and try searching for it by type:
mdfind "kMDItemContentType == com.apple.xcode.dsym"
or
mdfind "kMDItemContentType == public.jpeg"
You can find other types with mdls
Methods that work
.noindex
Naming a folder with the extension .noindex
mdutil
You can disable spotlight indexing on the whole volume, for example if the machine is a headless build machine, you can use mdutil
.
mdutil -i off /
Methods that DO NOT work
VolumeConfiguration.plist
I have spent some time revisiting the /System/Volumes/Data/.Spotlight-V100/VolumeConfiguration.plist
solution that used to work and it would seem that file will not change the indexing behavior, it only reflects the current state of the Exclusions
. You can no longer start and stop the mds
service without rebooting. Rebooting will display the Exclusion in Spotlight Privacy, but it does not work until you remove it and re-add it. It would seem we need a mach call to one or more services to emulate the behavior of the UI.
PLIST_BUDDY=/usr/libexec/PlistBuddy
SPOTLIGHT_PLIST=/System/Volumes/Data/.Spotlight-V100/VolumeConfiguration.plist
PRIVATE_FOLDER=${HOME}/hidden_folder
UPDATE_TIME=$(date +"%a %b %d %H:%M:%S %Z %Y")
if [ "$1" == "update" ]; then
mkdir -p "${PRIVATE_FOLDER}"
${PLIST_BUDDY} -c "Add :Exclusions: string '${PRIVATE_FOLDER}'" "${SPOTLIGHT_PLIST}"
${PLIST_BUDDY} -c "Set :ConfigurationModificationDate '${UPDATE_TIME}'" "${SPOTLIGHT_PLIST}"
fi
${PLIST_BUDDY} -c "Print :ConfigurationVolumeUUID" "${SPOTLIGHT_PLIST}"
${PLIST_BUDDY} -c "Print :ConfigurationModificationDate" "${SPOTLIGHT_PLIST}"
${PLIST_BUDDY} -c "Print :Exclusions" "${SPOTLIGHT_PLIST}"