AppleScript Dummy needs help debugging script to add drive to spotlight exclusions. Now necessary before external drive backups


Catalina 10.15.7

The script
System Pref → Spotlight → Click Privacy→ Click (+) does not work. Not even opening Spotlight

The rationale for the script.
I use a backup app for backups using external SSDs. , there is a bug whereby the backup ends up as a volume of the primary drive instead or in addition to the backup on the SSD. The developer suspects a conflict with Spotlight and suggests excluding my drive from Spotlight before running the backup, hence my terrible attempt at a script below. A similar problem had been described with multiple backup apps.

thanks very much

activate application "System Preferences"
tell application "System Events"
	tell process "System Preferences"
		click button "Spotlight" of scroll area 1 of window "System Preferences" of application process "System Preferences"
		click radio button "Privacy" of tab group 1 of window "Spotlight" of application process "System Preferences"
		click button 1 of group 1 of tab group 1 of window "Spotlight" of application process "System Preferences"
	end tell
end tell


Do you not just have to exclude your backup drive once then it persists?

You put the nail on the issue.
There is perhaps something I don’t understand.
I rotate external drives, but they all have the same name “RL CCC Backup”.
If I:

  • have 5 external SSD drives in a drawer next to my mac, and they are all named “RL CCC Backup”
  • only plug them one at a time to my mac, so there are never 2 external drives with the same name
  • plug one of the the “RL CCC Backup” SSD → add to sys pref privacy list → perform backup → eject → store off location at my friend’s home
  • even after ejecting the drive will continue to be listed in the privacy list (I checked this).

Question: if I plug in another external drive with the same name, will spotlight respect the exclusion based on the name only, or will spotlight index the new drive because it uses some kind of unique identifier, ie differentiates drives even if they have the same name ?

If privacy is based on name only, then it’s easy. I did not think so, but I may be wrong

thank you very much !

Presumably you could plug a drive in, set the setting, unplug it, then alternately plug it and then another in and test the spotlight searching to verify what happens with your setup.

How do I check for spotlight searching ? thank you

Search using spotlight for a file that is only on that drive. Since it is a backup drive you may well need to create such a file. A text file with a unique name should suffice.

1 Like

crystal clear. thanks very much

Just a follow-up. I carried out the test as you suggested and spotlight privacy appears to be based on the volume, name not a unique identifier.
Thank you very much for guiding me through this problem.