2

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?

  • Interesting case of automating an automation... May I ask what is your final goal? Maybe we can suggest another approach to your whole objective. – Mateus Ribeiro Nov 20 '18 at 16:52
1

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

  • how do you save the gifs? – Mateus Ribeiro Nov 21 '18 at 13:53
  • @MateusRibeiro I just use Mac’s built in screen recording to create a video recording of my screen actions. Then I load that video file into GIF Brewery 3 to make my edits and save as a .gif gifbrewery.com – wch1zpink Nov 22 '18 at 20:25
0

Similar in ilk to @wch1zpink's suggestion, I would consider formulating the Folder Action as a script rather than an Automator workflow, which would look something like this:

on adding folder items to directory after receiving fs

    do shell script "..."

end adding folder items to

Saving this as either a .scpt or .applescript file, and moving it to ~/Library/Scripts/Folder Action Scripts, you can then script the creation of folder actions and attach them to folders like this:

use sys : application "System Events"

property name : "abc"
property path : "/path/to/abc"
property folder action : a reference to folder action named (my name)
property script : "my folder action script.applescript"
property folder : a reference to Folder Action scripts folder
property file : a reference to the file named (my script) in my folder

set folder actions enabled to true

if not (my file exists) then return open my folder
if my folder action exists then return my folder action's scripts

make new folder action with properties {name:my name, path:my path}
tell my folder action to make new script with properties ¬
    {name:my file's name, POSIX path:my file's POSIX path}

set my folder action's enabled to true
set my folder action's scripts's enabled to true

where "my folder action script.applescript" is the name of your saved folder action script; and the properties name and path represent the name and path to your monitored folder.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .