Spotlight Utility (spotutil)

"spotutil" is a utility for enabling and disabling Spotlight on Mac OS X (10.4 and above).
It can be used four ways:

1.  sudo spotutil -S target_volume
This form gives you the indexing status of the target_volume.  No changes are made.
This is also the default action if you don't supply a dash-parm.

2.  sudo spotutil -E target_volume
This form will Enable Spotlight on the target_volume, if it is currently Disabled.

3.  sudo spotutil -D target_volume
This form will Disable Spotlight on the target_volume, if it is currently Enabled.
It retains the Spotlight databases in the .Spotlight-V100 folder.

4.  sudo spotutil -X target_volume
This form will Disable Spotlight on the target_volume, if it is currently Enabled.
It also deletes the Spotlight databases in the .Spotlight-V100 folder.
This is the most destructive option in spotutil.

Dash-parameters, like -D or -S, may be either UPPER or lower case, but may not be combined,
and there can only be one dash-parm, which must come first, followed by the target_volume.
If you leave it out the dash-parm, -S is assumed.

In all cases, target_volume is assumed to be at /Volumes/target_volume, and you
simply specify target_volume in quotes or with escaped special characters.  Do NOT
include the '/Volumes/' portion.  You can also specify just "/" or / to mean the boot volume.

For example:  a) Backup80
                       b) "Macintosh HD"
                       c) My\ Mini\ Disk      (imbedded blanks are escaped).
                       d) /

Specific example:  sudo spotutil -E "Macintosh HD"

You should download the attachment (spotutil) at the end of this page.  You may also download 'spotwrap' which is a wrapper script that takes care of 'sudo ' for you.
Spotwrap checks that you have 'spotutil' as an executable in the same directory as 'spotwrap'.  Make each executable with "chmod 755 spotwrap" and "chmod 755 spotutil".  Spotwrap is handy for us who forget to use 'sudo '.  You run spotwrap like this:  spotwrap -S /

Spotutil is designed to Enable or Disable Spotlight on Tiger (and above).  Each of these systems uses different indexing methods.  Tiger uses _IndexPolicy.plist and _rules.plist in the main /.Spotlight-V100 folder.  Leopards use VolumeConfig.plist in Store-V1 in /.Spotlight-V100, so the existence of Store-V1 indicates a Leopard indexing scheme.  In order to Disable Spotlight on these systems, the control files for these systems needs to be configured so that no system attempts to index the volume.  In addition, if indexing is currently enabled and actively running on a system, spotutil can stop it, and then configure /.Spotlight-V100 to be disabled on all systems.  This is important, especially for external disk drives that have multiple partitions (volumes), and the disk drive is mounted on Tiger and Leopard systems.  Most often, that's because one volume is being used for Tiger, and another volume on the same drive is being used for Leopard.  Backup volumes are good examples.  NOTE: Leopard in this document includes Snow Leopard.

There is a /.metadata_never_index file that, if it exists on a volume, signals Spotlight in these systems to NOT index that volume, regardless of control file settings in the /.Spotlight-V100 folder.  So when you request spotutil to Disable a volume, /.metadata_never_index is always added (if it doesn't exist).  When you Enable, that file is removed, and the appropriate controls are reset.  Note that Tiger's 'mdutil' only affects Tiger settings, and Leopard's 'mdutil' basically only affects Leopard settings.  You typically don't want indexing to happen on BOTH systems, so the spotutil -E option only tries to Enable for the system running 'mdutil'.  The volume with Store-V1 is a Leopard-based volume.  Otherwise, it is a Tiger-based volume.  spotutil only Enables the volume with the 'mdutil that matches the volume.  Since the volume was probably mounted with an existing /.metadata_never_index file, Spotlight won't respond to an Enable request until you dismount and then remount the volume.

There are two forms of Disable.  With the -D option, spotutil stops Spotlight (if actively indexing), and then configures the control settings for BOTH systems.  With the -X option, it does the same thing, and then deletes the corresponding index databases.  If you use -D, the indexes remain intact which allows Finder's 'find' command to continue to operate.  But the volume will no longer be actively indexed.

Now, what about "clone backups"?  These present a problem because a true clone would copy the /.Spotlight-V100 folder from the source volume to the target volume.  If the target volume is supposed to be a Disable volume, it could be reEnabled by virtue of the cloning process.  Fortunately, some backup software, like Data Backup from Prosoft Engineering, provide a means for "excluding" a folder from being copied, but leaves any existing version of that folder intact on the target volume.  So your Disabled /.Spotlight-V100 on the target remains unchanged if you "exclude" it from the source.

Carbon Copy Cloner (CCC) from Bombich Software does an even better job.  It ignores both .metadata_never_index and .Spotlight-V100 automatically.

To take care of /.metadata_never_index, I wrote an AppleScript (DataBkup.applescript) designed for use with Data Backup.  This script, as an application, checks you boot volume for /.metadata_never_index, and if it doesn't exist, it creates it.  Then it runs Data Backup.  When finished, if /.metadata_never_index was created, it removes it.  By doing this, your boot volume has /.metadata_never_index which is copied to your target volume (clone backup).  If you download the AppleScript, double-click it to launch the Script Editor, then "Compile" it and "Save As..." choosing the File Format: 'application', with Run Only (checked) and no Startup Screen (unchecked).  You may wish to check "Hide Extension".

Lastly, I've created a utility called "SpotSave" from "SpotSave.applescript" that copies your /.Spotlight-V100 folder from your hard-disk to a "CCC.Spotlight.archive" folder on your backup volume.  You do this AFTER completing a backup.  Just launch the "SpotSave.app" (saved where you like), and it looks at the mounted volumes, and prompts you with each name until you click on the name. Otherwise, use Next to see the next name.  Once you've made your selection, "SpotSave" copies your hard disk /.Spotlight-V100 folder to your backup.  If you ever restore from the backup, move the saved .Spotlight-V100 copy in CCC.Spotlight.archive to its final destination, replacing the disabled /.Spotlight-V100 folder. Remember to also remove "/.metadata_never_index" on your restored system.  You also need "spotsave" which is saved in /Users/Shared/spotsave .

SpotSave determines volumes just like my "TimeStamp" code. Since SpotSave also touches "CCC.timestamp", so it's a replacement for Timestamp.  "SpotSave.dmg" is a downloadable disk-image of the SpotSave app in Universal form (x86-64, i386, ppc7400).  It should run on almost any MacOS X system (10.4 or higher).  You still need the "spotsave" script in /Users/Shared/spotsave, included in SpotSave.dmg .
ċ
DataBkup.applescript
(4k)
Dick Guertin,
Jan 11, 2010, 10:03 PM
ċ
SpotSave.applescript
(2k)
Dick Guertin,
Oct 29, 2014, 1:28 PM
ċ
SpotSave.dmg
(78k)
Dick Guertin,
Oct 29, 2014, 2:26 PM
ċ
spotsave
(1k)
Dick Guertin,
Oct 17, 2014, 2:52 PM
ċ
spotutil
(9k)
Dick Guertin,
Jul 15, 2013, 11:12 PM
ċ
spotwrap
(0k)
Dick Guertin,
Nov 24, 2013, 5:19 PM