Skip to content

Instantly share code, notes, and snippets.

@mikemcduffie
Forked from christovic/AddSpotlightExclusion.sh
Created September 22, 2025 10:23
Show Gist options
  • Select an option

  • Save mikemcduffie/a35ebf58ef0674041d19b6b0bbfb960b to your computer and use it in GitHub Desktop.

Select an option

Save mikemcduffie/a35ebf58ef0674041d19b6b0bbfb960b to your computer and use it in GitHub Desktop.

Revisions

  1. @christovic christovic revised this gist Jun 26, 2020. 1 changed file with 14 additions and 5 deletions.
    19 changes: 14 additions & 5 deletions AddSpotlightExclusion.sh
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,27 @@
    #!/bin/bash
    !/bin/bash

    cd /System/Volumes/Data/.Spotlight-V100
    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} /System/Volumes/Data/.Spotlight-V100/VolumeConfiguration.plist
    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.
    echo Already in array, not doing anything.
    fi

    # Now we restart mds to apply the changes
  2. @christovic christovic created this gist May 22, 2020.
    20 changes: 20 additions & 0 deletions AddSpotlightExclusion.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/bin/bash

    cd /System/Volumes/Data/.Spotlight-V100

    # 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} /System/Volumes/Data/.Spotlight-V100/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