Here’s a simple solution to a trivial annoyance.

The annoyance:

You use removable drives to create a clone of your startup drive, or some other drive, using SuperDuper, DataBackup or similar software.

If you have Spotlight running, it will begin indexing the removable drive when you mount it, which in turn will make your cloning process take nearly twice as long.

You’d like to disable Spotlight indexing on the removable (or any other) drive.

Of course the problem is infinite, since if Spotlight is indexing the source drive, then when the clone is complete, it will have indexing enabled on the destination too.

Well, there’s always the privacy option in system preferences, but if you’re like me, it’s pretty much hit or miss, and I generally have to redo it each time. (Not sure what the logic is with it, but it certainly doesn’t remember the privacy state of removable drives.)

And there’s Spotless. Nice product, which I use myself. But with removables, Spotless has no effect unless it is running at the same time as you mount the drive.

Finally, there’s the hidden file ".metadata_never_index" which works to prevent a drive from being indexed, but most folks have a hard time creating it... and the cloning issue mention above still applies - if Spotlight is indexing the source drive, then when the clone is complete, it will have indexing enabled on the destination too.

The solution

...and once you’ve set it up, it only requires a single drag and drop after the clone is finished copying.

Create a drag and drop AppleScript that will install the ".metadata_never_index" file on the drive.

How is that different that using system preferences? Number of steps. 

My script: 
1) drag and drop

System preferences:
1) open system preferences
2) open spotlight
3) switch to privacy
4) drag and drop
5) close system preferences


(BTW, these are very stripped-down scripts, with almost NO error checking. I will accept no liability whatsoever for your use of these scripts... you’re on your own. If you’re the litigious type, quit here.)

First, you need the drag and drop application, which is available by clicking here.

What you're getting in the download (above.)

(See bottom of page for a better solution! **)


Here is the complete text of the Applescript I used for creating the file.

on open these_items
set x to the count of these_items
if x is 1 then
set this_item to (item 1 of these_items)
do shell script "touch \"" & POSIX path of this_item & "\".metadata_never_index"
end if
end open


Now, when you want a volume to not be indexed, you will just drag and drop it on "NeverIndex".

You will not
see anything happen, but what does happen is that an invisible file named ".metadata_never_index" is written to the root level of the drive.

(Note: the
very first time you do this, you will still see Spotlight indexing the drive. That is because the presence of that file is recognized only when the drive is first mounted, and since you have already mounted it before creating the ".metadata_never_index" file, Spotlight will not recognize it, and will begin indexing. The next time you mount it, Spotlight will not index it.)


Here’s how to use it:

When you are creating a clone, and your source does
not have the ".metadata_never_index" file on it (because you do want Spotlight to index it) SuperDuper will dutifully erase it from the destination drive too (else it would not be a clone, would it?) 

SO.... once you're done with the cloning operation, drag and drop the newly updated clone on "NeverIndex", so that it can
put back the ".metadata_never_index" file.  Now eject it.

From then on when you are making a clone, you will:

1) mount the drive (it will not be indexed because it has ".metadata_never_index")
2) create your clone with DataBackup, SuperDuper, et al
3) when finished, drop the file on "NeverIndex" to reinstall the ".metadata_never_index" file
4) eject the volume

As you can see, all you've done is add one step: number 3 above.
(** see below)

(FWIW, I’ve sent off a suggestion to Dave for SuperDuper that he add ".metadata_never_index" to his software, so the when it restores the Spotlight state, it will restore that file too. If that should be implemented, then all one would need is the first-time creation of the ".metadata_never_index" file, as SuperDuper will restore it when the cloning is finished. He replied that he’s looking into it, but for now, the above scenario will have to be followed.)

By the way, here's the code for removing the ".metadata_never_index" file:

on open these_items
set x to the count of these_items
if x is 1 then
set this_item to (item 1 of these_items)
do shell script "rm \"" & POSIX path of this_item & "\".metadata_never_index"
end if
end open

This is the code I used in the "RemoveNeverIndex" script, included in the download.


** better solution


Finally, here is another version of the "never_index" code, called "CloneEject", which will also eject the drive after creating the never_index file:


on open these_items
set x to the count of these_items
if x is 1 then
set this_item to (item 1 of these_items)
do shell script "touch \"" & POSIX path of this_item & "\".metadata_never_index"
delay 1
--if you include the following line, the program will also unmount the drive
-- after creating the never-index file.
do shell script "hdiutil unmount \"" & POSIX path of this_item & "\""
-- you must wait several seconds for the drive to unmount from the desktop
-- do not remove the drive until its icon has disappeared!!!
end if
end open
quit

Here: step by step is how you make the application


1) run Script Editor (which is probably in your Applications/Applescript folder)

2) if it does not open a new blank window, choose file/new

3) copy and paste the code into the window

4) choose File/save as...

5) from the file format popup, choose "application bundle"

6) save it with a name you'll recognize, in a place you can find it, like the desktop.