Skip to content

Instantly share code, notes, and snippets.

@christovic
Last active January 31, 2024 01:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christovic/c9aef6c1aa5f6aa258ea8f12e4c10724 to your computer and use it in GitHub Desktop.
Save christovic/c9aef6c1aa5f6aa258ea8f12e4c10724 to your computer and use it in GitHub Desktop.
!/bin/bash
launchctl stop com.apple.metadata.mds && launchctl start com.apple.metadata.mds
vers=$( sw_vers | grep BuildVersion | awk '{print substr($2,0,2)}' )
sdir="/.Spotlight-V100"
if [[ "${vers}" > "18" ]]; then
sdir="/System/Volumes/Data${sdir}"
fi
cd "${sdir}"
# First let's check if the directory we're adding already exists
search_string=$1
let index="`plutil -extract Exclusions xml1 -o - VolumeConfiguration.plist | grep string | grep -wn "${search_string}" | cut -d ':' -f 1` - 1"
if [ $index -lt 0 ]; then
echo Not in array, let\'s add it in.
plutil -insert Exclusions.0 -string ${search_string} "${sdir}/VolumeConfiguration.plist"
else
echo Already in array, not doing anything.
fi
# Now we restart mds to apply the changes
launchctl stop com.apple.metadata.mds && launchctl start com.apple.metadata.mds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment