Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Prevent Spotlight from indexing external hard drives Storage Devices
If you, like me, get annoyed by the index files Spotlight creates any time you create an external hard drive, you might want to try this hint. We're going to set up a launchd service which runs a script every time a hard drive is mounted. This script will touch the .metadata_never_index file (which prevents Spotlight from creating the index; see this hint) on the hard drive.

Let's start with the launchd service. Open Terminal and type the following, then press Return:
$ cd ~/Library/LaunchAgents/ 
Create the file com.index.no_index.plist with your favorite editor (vi, nano, etc.), and insert the following XML code:
 
<?xml version="1.0" encoding="UTF-8"?>
<?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>com.index.no_index</string>
	<key>Disabled</key>
	<false/>
	<key>Program</key>
	<string>/Users/*YOUR_NAME*/no_index</string>
	<key>StartOnMount</key>
	<true/>
	<key>RunAtLoad</key>
	<false/>
	<key>KeepAlive</key>
	<false/>
	<key>EnableTransactions</key>
	<true/>
</dict>
</plist>
Do not forget to change *YOUR_NAME* to the name of you home folder. If you don't know what to put there type echo $HOME in Terminal.

Now we create the actual script. Go to you home folder by typing cd ~ , and create a file named no_index with your favorite text editor, with these contents:
#!/bin/bash

for filename in /Volumes/*
do
  if [[ $filename != "/Volumes/Macintosh HD" && $filename != "/Volumes/BOOTCAMP" ]]
then
  file=$filename"/.metadata_never_index"
  touch "$file"
fi
done;
You may want to make the file executable with chmod +x no_index . Now everything is set up, and we can start the service with this command: launchctl load -w ~/Library/LaunchAgents/com.index.no_index.plist

I hope everything will work for you; for me, it works very well in Snow Leopard.

[robg adds: I haven't tested this one.]
    •    
  • Currently 2.84 / 5
  You rated: 3 / 5 (19 votes cast)
 
[24,820 views]  

Prevent Spotlight from indexing external hard drives | 6 comments | Create New Account
Click here to return to the 'Prevent Spotlight from indexing external hard drives' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Prevent Spotlight from indexing external hard drives
Authored by: wallybear on May 03, '10 08:12:21AM

Beware: this script assumes that you have only ONE partition on your drive (or two, with one used for BootCamp), named "Macintosh HD" (the default name used by Apple).
If you have renamed your drive or if you have, like me, multiple partitions and/or internal drives, you have to correct the script accordingly, or Spotlight will stop working on your internal drive(s).



[ Reply to This | # ]
Prevent Spotlight from indexing external hard drives
Authored by: fulmar2 on May 03, '10 08:23:34AM

Is this different from going to System Preferences -> Spotlight -> Privacy, and then selecting the external disk that you do not want to index? I do that for my external drives... But was wondering if this hint is any different. It is certainly easier to use the GUI if they accomplish the same thing.



[ Reply to This | # ]
Prevent Spotlight from indexing external hard drives
Authored by: mvier on May 04, '10 05:58:00AM

I second your comment. Why the complication ? Just set the privacy settings to ignore that particular external drive and you're done !



[ Reply to This | # ]
Prevent Spotlight from indexing external hard drives
Authored by: ChipMck on May 07, '10 07:14:42AM

When the volume is unmounted/ejected, the privacy setting usually gets lost.



[ Reply to This | # ]
Prevent Spotlight from indexing external hard drives
Authored by: DaijDjan on May 03, '10 09:18:49AM

works :)
I changed the names as needed -- tada



[ Reply to This | # ]
Prevent Spotlight from indexing external hard drives
Authored by: TvE on May 04, '10 01:19:31PM
It is very "optimistic" to hardcode filenames. Personally I change the name of my boot disks to represent the hostname of the Mac, making it easier to prevent mistakes ;-)

I have a script that measures disk usage on external disks (ie NOT the boot volume) and I use this test command to filter out the boot volume:
if [ ! -L "$file" ]; then	# No symlinks (=> do not measure the boot disk)


PS You can read more about the command "test" (or "[" as it is called ;-) here: http://tldp.org/LDP/abs/html/fto.html
Edited on May 04, '10 01:23:18PM by TvE


[ Reply to This | # ]