How to add Automator Folder Action from command line

automatorcatalinamojave

Is there a way to add Folder Action to Automator tool from the command line?

When I typed Automator I get very basic CLI options (-D, -i, -v)..
Can someone please add an example of how to do it?

Best Answer

See Attaching a Folder Action using Applescript for an AppleScript, an Open Scripting Architecture (OSA) language, solution. You can use osascript on the command line to run OSA scripts:

Your syntax was OK in old versions (at least up to macOS 10.6.8). Since it has been depreciated and it must be replaced by "make" :

tell application "System Events"
    make new folder action at end of folder actions with properties {enabled:true, name:"FolderName", path:"path:to:my:folder}
    tell folder action "FolderName" to make new script at end of scripts with properties {name:"myScriptName.scpt"}
end tell