How to fix non-working Folder Action on an external hard disk
I had a problem with Folder Actions: they always stopped working after a while! Quite annoying. After some digging on Google, I found one post on MacOSXHints forums where a user mentioned that a FA attached to a folder on an external HDD would always stop working after un-mounting / re-mounting the hard disk; exactly what was happening to me! So I started fiddling with AppleScript, and found a way to detach then re-attach a FA associated with a folder. Next, to automatize the execution of this fix, I needed a way to execute it when my external HDD was mounted. Another FA to the rescue, this one attached to the /Volumes folder. Each time a new folder would appear in /Volumes (like my USB drive for example), my FA script would be executed, and it would detach then re-attach the original FA script.
on adding folder items to target_folder after receiving added_items
set volumeName to “USBDrive1” – This is the display name of your external HDD volume; any of them if you have more than one.
repeat with added_item in added_items
if the displayed name of (info for added_item) is equal to volumeName then
quit application “System Events”
end adding folder items to
tell application “System Events”
– Detach Folder Action
delete folder action “TV Shows” – This should match the name of the folder you’ll attach the FA to; i.e. to attach a FA to “USBDrive1:Music:TV Shows”, use “TV Shows” here.
-- Re-Attach Folder Action attach action to folder "USBDrive1:Music:TV Shows" using "Mac Mini HD:Users:me:Library:Scripts:Folder Action Scripts:Import TV shows into iTunes.scpt" -- First parameter is the folder you want to attach to, the second is the scpt file you want to execute as a FA for that folder. end tell
To use this script: Attach this FA script to the /Volumes folder and it should fix this problem.
To attach a FA to /Volumes, hit Cmd-Shift-G after clicking the + in the folder column of Folder Actions Setup.app, and enter “/Volumes” then click Go, then Open.