'do not index this device' macro

Hello,
I have problems with overheating (loud fan) when I do an image backup to an external drive because spotlight actively indexes it. I can see this in activity monitor, and the fact that all is resolved if I add the external device to the spotlight privacy tab. In addition, spotlight blocks the ability to eject the drive.
is it possible to create a macro that would allow me to add / remove a device to / from the spotlight privacy tab?
thanks very much

Spotlight can be controlled with the mdutil tool, which you can run from an Execute Shell Script action. You may need to run as root (ie sudo mdutil) which provides challenges - you can allow specific commands to be run as root in the sudoers file, using appropriate caution.

1 Like

Another approach is to create a .metadata_never_index file at the root of the volume. You can also do this with KM with an Execute Shell Script action:

touch /Volumes/<volume-name>/.metadata_never_index

This will disable Spotlight indexing and search on the volume. It doesn’t require sudo.

After creating the file you have to unmount/mount the volume once to make it active. When backing up / cloning make sure the file doesn’t get deleted.

To check the Spotlight status of a volume use mdutil -s /Volumes/<volume-name>

3 Likes

thank you very much Peter. Sorry for the dealy.

thanks very much Tom, and sorry for the delay.

In terms of syntax, how do you write the volume name (as in in /Volumes//.metadata_never_index) when the volume name contains spaces ?

example: Volume name: Ronald accounting files

another question: what does Touch in the command mean?

thanks again very much Tom !

You can escape spaces with \:

touch /Volumes/Ronald\ accounting\ files/.metadata_never_index

or you can quote the whole path:

touch "/Volumes/Ronald accounting files/.metadata_never_index"

or

touch /Volumes/"Ronald accounting files"/.metadata_never_index

In this case, it just creates the file.
(If the file already exists, it updates the modification and access time.)

See man page.

2 Likes

outstanding. Thank you so much