По какой-то причине они всегда были скрыты, но в словаре сценариев Системные события есть команды attach action to
и remove action from
. Синтаксис также немного изменился во времена Snow Leopard, что тоже не помогло. Обработчик общего назначения для присоединения сценариев действий с папками (протестирован в Мохаве) будет выглядеть примерно так:
on run -- example
set theFolder to (choose folder with prompt "Choose folder to attach:" default location path to desktop)
set theScript to (choose file with prompt "Choose folder action script:" default location path to Folder Action scripts)
tell application "System Events" to set theName to name of theScript
attachAction(theFolder, theName)
end run
on attachAction(folderPath, scriptName)
(*
attach a script from "~/Library/Scripts/Folder Action Scripts" to a folder
parameters - folderPath [text or alias]: the folder to attach to
scriptName [text]: the name of the script to attach
returns [boolean]: true if successfully attached, false otherwise
*)
tell application "System Events"
try -- enable existing folder action
set folderName to name of disk item (folderPath as text)
set enabled of folder action folderName to true
on error errmess -- create new
log errmess
try
make new folder action at end of folder actions with properties {enabled:true, name:folderName, path:folderPath}
on error errmess -- oops (bad path, etc)
log errmess
return false
end try
end try
try -- enable existing folder action script
tell folder action folderName to set enabled of script scriptName to true
on error errmess -- create new
log errmess
try
tell folder action folderName to make new script at end of scripts with properties {name:scriptName}
on error errmess -- oops (bad name, etc)
log errmess
return false
end try
end try
return true
end tell
end attachAction