How can I check and set the state of an attached folder script?

G’day

I’ve got a heap of folders with the same script attached.

I want to automate the adding of a folder action to each folder. I can set the folder action for new folders, but can’t find how to check the enabled of the existing attached script.

Anyone know how please?

Regards

Santa


set p2ftpDownloads to ((path to desktop) & "ftp Downloads") as text
set p2me to path to of me
tell application "Finder" to set p2cofme to container of (path to me) as text
set p2FAS to (path to Folder Action scripts folder) as text

set saveFolderAction to (p2cofme & "ftp Downloader.scpt") as text
try
	tell application "Finder"
		if exists file ((p2FAS & "ftp Downloader.scpt") as text) then
			move file "ftp Downloader.scpt" of folder p2FAS to trash
		end if
		copy file saveFolderAction to folder p2FAS # 'with replacing' not allowed
	end tell
on error errmsg
	display dialog errmsg
end try

tell application "Finder"
	set TempList to folders of folder p2ftpDownloads as list
end tell
tell application "System Events"
	set folder actions enabled to true
	repeat with eachFolder in TempList
		try
			attach action to (eachFolder as alias) using ((p2FAS & "ftp Downloader.scpt") as text)
			say name of eachFolder as text
		on error errmsg number errNum
			if errNum = -48 then -- Folder action already exists, but is it active?
				if not (folder action "ftp Downloader.scpt" of eachFolder is enabled) then # doesn't work
					--set enabled of eachFolder's folder action (("ftp Downloader.scpt") as text) to true
				end if
			end if
			display dialog errmsg & return & errNum
		end try
	end repeat
end tell

It’s ok, I solved it

Regards

Santa


tell application "System Events"
	set temp to folder actions
	repeat with eachFolder in temp
		set FAScripts to name of every script of eachFolder
		if "ftp Downloader.scpt" is in FAScripts then
			if enabled of eachFolder is true then
				display dialog (name of eachFolder as text) buttons {"Keep ON", "Turn OFF"}
				if button returned of the result = "Turn OFF" then set enabled of eachFolder to false
			else
				display dialog (name of eachFolder as text) buttons {"Turn ON", "Keep OFF"}
				if button returned of the result = "Turn ON" then set enabled of eachFolder to true
			end if
		end if
	end repeat
 end tell