Attaching folder actions

I am trying to write a script that attaches an action to folders as they are created (or added to an existing folder) using a folder action. So far, I have:

on adding folder items to this_folder after receiving these_items
	tell application "System Events"
		attach action to (these_items whose class is folder) ¬
			using "Macintosh HD/Library/Scripts/Folder Action Scripts/myScript.scpt"
	end tell
end adding folder items to

Unfortunately, this passes the syntax check, but doesn’t work as planned. Does anyone see the problem?

Also, I would like to be able to check folders to see if they already have the action attached, so that when I move a folder into a folder running the above action, it won’t attach the script again. How can you test what actions are attached to a folder?

Attach Action To wants a reference to a folder to act on and you’re passing it a list. Further, “using” in that statement almost certainly requires the HFS form of the script path, i.e. using POSIX file “as/you/have/it”

Thank you! Problem solved.

For posterity’s sake, the correct implementation reads:

on adding folder items to this_folder after receiving these_items
	repeat with this_item in these_items
		if folder of (info for this_item) is true then
			tell application "System Events"
				attach action to this_item ¬
					using ":Macintosh HD:Library:Scripts:Folder Action Scripts:myScript"
			end tell
		end if
	end repeat
end adding folder items to

Posterity thanks you! :smiley:

How about this part?

Hi,

with


tell application "System Events" to get path of folder actions

you get a list of the hot folders (alias list)