Help converting Applescript from drag-and-drop to Folder Action

Hello All,

I’ve recently discovered an Applescript created by Tracy Valleau called CloneEject (aka StopSpotlight):

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
do shell script “hdiutil unmount "” & POSIX path of this_item & “"”
end if
end open

This script prevents Spotlight from indexing external drives. It works like this: drag a volume onto this Applescript Application and a file is written to the drive to prevent spotlight from indexing it (.metadata_never_index), then the drive is ejected and manually re-mounted (so Spotlight sees the dot-file and doesn’t index it).

I’m wondering if it’s possible to make this a folder action (in /volumes) so when a volume is mounted it runs automatically (but also checks to see if .metadata_never_index already exists so it doesn’t run an infinite loop). I tried converting it to a script and adding as a folder action, but nothing happens when a volume is mounted (perhaps because it starts with “on open” instead of “on mount”?). I think the code would only need a small tweak, but really have no idea where to start (I’m a super applescript newbie).

Can anyone tweak this to get it working as a folder action? Or give an suggestions or other places to look?


Without considering your script (which I didn’t check), you should know that Folder Action scripts MUST be placed in ~Library/Scripts/Folder Action Scripts/. If that folder doesn’t exist, create it. Log out and in again so the Finder will find the script.

thanks - i’m aware of the folder actions scripts folder.