How to deploy Automator workflow to clients

automationautomatorscript

For a specific use case, I've developed a Folder Action workflow with Automator. When a file gets created in a folder 'abc', the workflow kicks of and executes a shell script.

This workflow needs to be installed / deployed to many client machines in corporate environments. While end users could be provided the setup instructions, this approach is prone to errors so I'm looking for a better approach.

I'm aware that the actual workflow definition gets stored in:

/Users/[user]/Library/Workflows/Applications/Folder Actions/*

While the *.workflow/Contents/document.wflow does includes the folderActionFolderPath, copying the workflow from one client to another does not work as the Folder Action does not get enabled. It still needs to be enabled in Finder (Home folder –> right click on the folder –> Selecting 'Folder Action Setup…' from the drop down menu). I haven't found a way to automate this configuration step from the command line.

How can a system administrator install a Folder Action workflow on several client machines?

Best Answer

If you really want to “idiot proof” the process, here is option. In Script Editor.app, create a new blank document then immediately go and save it as an application (I saved mine as “JIMZ Attach Folder Action.app”)

The purpose of this application would be to copy the Automator workflow file (which will be included within the “Resources” folder of this new application you just created in Script Editor ) that you want attached to the “ABC” folder on any user’s computer, to the necessary “Folder Actions” folder on that computer. If the “ABC” folder does not exist on the target computer, it will be created. For purposes of this project, the “ABC” folder location would be on the target computer’s desktop.

Paste this following code into your new blank AppleScript app that you just created.

property nameOfTriggerFolder : "ABC"
property pathToFolderActions : ((path to workflows folder as text) & "Applications:Folder Actions:")
property attachFolderActionTo : (path to desktop as text) & nameOfTriggerFolder

set resourceName to "ABC Folder Action.scpt"
set folderActionScript to ((path to me as string) & "Contents:Resources:" & resourceName) as string

tell application "Finder"
    if not (exists of folder attachFolderActionTo) then
        make new folder at (path to desktop) with properties {name:nameOfTriggerFolder}
    end if
    duplicate file folderActionScript to folder pathToFolderActions with replacing
end tell

tell application "Folder Actions Setup"
    activate
    try
        set addedFolderAction to make new folder action with properties {name:nameOfTriggerFolder, path:attachFolderActionTo}
    end try
    try
        delay 0.5
        tell addedFolderAction to make new script with properties {name:resourceName, path:(pathToFolderActions & resourceName)}
    end try
    if not folder actions enabled then
        set folder actions enabled to true
    end if
end tell

Then go ahead and drag your Automator workflow file from Finder app directly to the resources folder in Script Editor (as shown in the animation below)

enter image description here

Compile and save the app in Script Editor. Now you can distribute this app to whoever you want. When this app is now launched on any target computer, it will copy the Automator workflow file directly to the folder where it needs to be located. It will also add the “ABC” folder to the list of enabled folders in the Folder Actions Setup.app and attach the script or workflow file to that folder