9

Using Mavericks, how can I prevent Spotlight from indexing all drives except my primary internal drive? In my work, I connect dozens of new drives every week, and I do not want the .Spotlight-V100 folder to be created on them.

I know I can add each drive to the Spotlight privacy list, but that can only be done after connecting the drive, and then the .Spotlight-V100 folder has already been created.

I could disable Spotlight completely, but then I lose the convenience of indexing my internal drive. I want to use Spotlight for my internal drive only, and disable it for all other drives, including ones that have yet to be connected.

1
  • something like disable the USB port ?
    – Ruskes
    Commented Jun 26, 2014 at 7:50

2 Answers 2

4

A file called

.metadata_never_index

place in the root of any volume will suppress indexing behaviour.

You can generate this file automatically

the following files need to be created as root

the following shell script will create the requisite file should an active (less than 30 days old) spotlight entry not be found.

/var/root/unindex.sh

to create this

sudo vi /var/root/unindex.sh

or use your preferred text editor

The contents should be

#!/bin/bash
# suppress spotlight indexing of new volumes
# pc 26-june-2014 v0.1
# v 0.2 27-june-2014 add mdutil

# get the last volume mounted

vol=$(df)
vol=${vol##*%}
echo $vol




# is this a volume that has been indexed in the past month

count=$(find ${vol}/.Spotlight-V100 -mtime -30 | wc -l )
[[ $count -gt 1 ]] && {

# then it remains so

logger -t unindex spotlight activity detected in last 30 days
exit 0
}

# else create index supression file
logger -t unindex creating ${vol}/.metadata_never_index
touch ${vol}/.metadata_never_index
# and stop spotlight indexing the drive
logger -t unindex mdutil -i off /Volumes/${vol}
mdutil -i off /Volumes/${vol}

make sure it can be executed...

sudo chmod a+x /var/root/unindex.sh

now add an entry to launchd, create the file

/Library/LaunchDaemons/org.misctools.unindex.plist

to create this

sudo vi /Library/LaunchDaemons/org.misctools.unindex.plist

with contents

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.misctools.unindex</string>
    <key>ProgramArguments</key>
    <array>
        <string>/var/root/unindex.sh</string>
    </array>
    <key>RunAtLoad</key>
    <false/>
    <key>StartOnMount</key>
    <true/>
</dict>
</plist>

now activate the job

sudo launchctl load /Library/LaunchDaemons/org.misctools.unindex.plist

the job will launch every time you mount a disk, look in the console for messages filtered by 'unindex' for it's actions e.g. from my machine

 26/06/2014 09:02:35.824 unindex[1362]: creating /Volumes/hfs/.metadata_never_index
5
  • Very thorough answer, thank you. I'll give this a try tomorrow. I wasn't aware of the StartOnMount feature. Are you sure this script will run fast enough, before Spotlight starts indexing?
    – Elliott
    Commented Jun 26, 2014 at 20:29
  • It worked on one drive, but not on another. The syslog shows Spotlight working just before unindex starts. Jun 26 19:33:00 macpro mds[12724]: (Normal) Volume: volume:0x7fa145816800 ********** Bootstrapped Creating a default store:3 SpotLoc:/Volumes/B025_0626AI/.Spotlight-V100 SpotVerLoc:/Volumes/B025_0626AI/.Spotlight-V100/Store-V1 occlude:0 /Volumes/B025_0626AI Jun 26 19:33:00 macpro unindex[13367]: creating /Volumes/B025_0626AI/.metadata_never_index
    – Elliott
    Commented Jun 27, 2014 at 2:35
  • Looks like it may be failing on drives with no spotlight folder Commented Jun 27, 2014 at 11:49
  • It seems to be random. I've tried about a dozen drives today, none of which contain a Spotlight folder. For half of them, your script runs first, while the other half run Spotlight first.
    – Elliott
    Commented Jun 27, 2014 at 16:17
  • 1
    Ok, I've used njboots suggestion of mdutil to explicitly stop spotlight indexing the volume. Spotlight and the Mount event are run asynchronously, so it's random which one gets in first . The edit is in the unindex.sh file. Commented Jun 27, 2014 at 16:55
3

Use the command line tool mdutil.

For example, say you connect an HFS+ journaled volume named "LEAVE_ME_BE"

Use the following command to disable indexing of the volume. If ownership is enabled, running as sudo may be necessary:

sudo mdutil -i off /Volumes/LEAVE_ME_BE

Check indexing status of all connected volumes:

mdutil -s /Volumes/*

Read the man page linked above for further options.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .