Fixing Automator Workflow Folder Action Plug-Ins in Leopard
Automator offers a variety of options when saving workflows in Mac OS X. Workflows can be saved as workflow files (to be opened and run within Automator), applications (to be run outside of Automator), or plug-ins (to be run from various processes within the operating system).
One type of plug-in that Automator supports is a Folder Action workflow. A workflow of this nature is attached to a specified folder. Once attached, whenever items are placed into the folder, they are passed to the workflow for processing.
Figure 1 Example of a Folder Action workflow
To save the workflow, choose File > Save As Plug-in (see Figure 2).
Figure 2 Starting the save process for the workflow
Next, enter a name for the workflow, and save it as a Folder Action plug-in, attached to a specified folder (see Figure 3).
Figure 3 Finishing the save process
Folder Actions themselves don’t actually run Automator workflows. Folder Actions are a feature of the operating system that was designed to trigger AppleScripts when an attached folder encounters certain events, such as opening a folder, closing a folder, adding items to a folder, and so forth.
When you save an Automator workflow as a Folder Action plug-in, Automator actually saves your workflow as an application into the ~/Library/Workflows/Applications/Folder Actions/ folder. It then creates an AppleScript file in the ~/Library/Scripts/Folder Action Scripts/ folder and attaches it to the folder you’ve specified.
So it’s the AppleScript that actually gets triggered when items are added to the folder. Once triggered, the AppleScript takes the added items and passes them to the workflow application for processing.
Folder Actions have been part of the Mac OS for some time now, but Leopard introduced some changes, designed to make Folder Actions more reliable. Probably the most significant, is that Apple made Folder Actions part of the file system instead of the Finder.
Personally, I’ve been having some trouble getting Automator Folder Action plug-in workflows to run properly in Leopard. I’m not sure exactly what’s wrong (looks like a possible bug), but in any case, I think that I’ve identified a workaround. I thought I would share this workaround here, in case others are experiencing the same problems.
First, let me explain the problems I’m seeing. Once I save an Automator workflow as a Folder Action plug-in, whenever I drop items into the attached folder, I typically see one of two things occur:
- The workflow launches in my Dock, but does nothing.
- The workflow launches, runs the first action in the workflow, and then stops.
To get around this problem, I’ve identified the following steps:
- Hold down the Control key and click on the attached folder to display the Finder’s contextual menu.
- Choose More > Edit a Folder Action > Folder Action
Name.scpt (see Figure 4).
Figure 4 Editing the AppleScript behind a Folder Action Workflow
Script Editor launches, and the AppleScript that triggers the Automator workflow is displayed.
- The AppleScript is displayed in Script Editor as follows (see Figure
on adding folder items to this_folder after receiving added_items tell application "Macintosh HD:Users:MyUserName:Library:Workflows:Applications:Folder Actions:Name Of My Workflow.app" open added_items end tell end adding folder items to
Figure 5 Original Folder Action AppleScript
This script tells the workflow itself to open any items that are added to the folder.
- Change the AppleScript to the following (see Figure 6):
on adding folder items to this_folder after receiving added_items tell application "Finder" open added_items using alias "Macintosh HD:Users:MyUserName:Library:Workflows:Applications:Folder Actions:Name Of My Workflow.app" end tell end adding folder items to
Figure 6 Modified Folder Action AppleScript
This revised script tells the Finder to open the added items using the workflow.
What’s the difference? Instead of asking the workflow itself to open the items, the Finder is essentially doing the equivalent of dragging and dropping the added items onto the workflow.
- Save and close the AppleScript.
That should do it. While I can’t guarantee that this workaround will help everyone, for me, it fixes the Folder Action problems that I was encountering. Now whenever I add items to the folder, they are successfully processed by my Automator workflow.