G’day scripters
Thanks to Yvan, I’ve solved my problem.
However, two thing arose from trying to use Yvans MacScripter posting, and also merging ‘attach action’, which I posted....
1. If the ‘attach action’ is called more than once on a given folder, a second, third, fourth, etc, attachment is made. The command does not check that it’s already attached.
2. Yvans script did not restrict itself to folders within another folder, but was a 'blanket’ approach.
So, if you’re interested, this version restricts to a given folder, and checks if the Folder Action is already attached.
If anyone can spot any problems with the code, I’d appreciate knowing about it, please.
Regards
Santa
on run
set path2DesktopftpDownloadsFolder to ((path to desktop) & "ftp Downloads") as text # Our required Folder Actions folders container folder
set path2FolderActionsScriptsFolder to (path to Folder Action scripts folder) as text
tell application "Finder" to set everyftpDownloadsFolder to every folder of folder path2DesktopftpDownloadsFolder as list
tell application "System Events"
set p to 0
set folder actions enabled to true
set FolderActionNames to name of every folder action
set FolderActionPaths to path of every folder action
repeat with i from 1 to count FolderActionPaths
set item i of FolderActionPaths to item i of FolderActionPaths as text
end repeat
repeat with theFolderAction from 1 to count of everyftpDownloadsFolder
try
set eachFolderPath to item theFolderAction of everyftpDownloadsFolder as alias as text
set foundMatchingAction to false
set p to 1
if (count FolderActionPaths) > 0 then
set FAScripts to name of every script of folder action theFolderAction
else
set FAScripts to {}
end if
set p to 6
if "ftp Downloader.scpt" is not in FAScripts then
set p to 7
attach action to folder eachFolderPath using ((path2FolderActionsScriptsFolder & "ftp Downloader.scpt") as text)
end if
if foundMatchingAction then
set p to 10
if enabled of folder action eachAction is false then
set enabled of folder action eachAction to true
end if
end if
on error errmsg
display dialog "Setting Folder Action for 'ftp Downloads' folder folders. " & return & return & errmsg & " p = " & p
end try
end repeat
end tell
end run