I’m trying to have Hazel run an Automator workflow when files are dropped in a folder (don’t use Folder Actions - too buggy), but I get an error when triggering it from Hazel:
2014-02-11 23:00:04.093 hazelworker[2607] Error executing Automator workflow /Volumes/work/Archice - Hazel.workflow: Error Domain=com.apple.Automator Code=-212 "The action “Run AppleScript” encountered an error." UserInfo=0x7fae91c71370 {NSLocalizedDescription=The action “Run AppleScript” encountered an error., NSLocalizedFailureReason=The operation couldn’t be completed. (com.apple.Automator error -212.), NSLocalizedRecoverySuggestion=Check the actionʼs properties and try running the workflow again.}
However running the Automator script manually on the file works perfectly.
The part of the Automator script that fails with Hazel is this, which basically depending on whether or not the preceding spotlight search finds any folders, disables some coming actions in the workflow, while enabling others. Basically some primitive if/else statements.
UPDATE: I've checked and it also fails as a service. I'm wondering if it's a problem with the way on refers to the workflow - the "of front workflow part"). What other ways could one refer to the workflow then...
Any ideas on how I can fix this?
- Code: Select all
on run {input, parameters}
set currentAction to index of current action of front workflow -- the most recent completed action
if input is {} then -- if no input - can't find existing project folder - then disable the following actions
tell Automator action index (currentAction + 2) of front workflow to set enabled to false
tell Automator action index (currentAction + 3) of front workflow to set enabled to false
tell Automator action index (currentAction + 4) of front workflow to set enabled to false
tell Automator action index (currentAction + 5) of front workflow to set enabled to false
tell Automator action index (currentAction + 6) of front workflow to set enabled to false
tell Automator action index (currentAction + 7) of front workflow to set enabled to false
tell Automator action index (currentAction + 8) of front workflow to set enabled to false
tell Automator action index (currentAction + 9) of front workflow to set enabled to true
tell Automator action index (currentAction + 10) of front workflow to set enabled to true
tell Automator action index (currentAction + 11) of front workflow to set enabled to true
tell Automator action index (currentAction + 12) of front workflow to set enabled to true
tell Automator action index (currentAction + 13) of front workflow to set enabled to true
tell Automator action index (currentAction + 14) of front workflow to set enabled to true
tell Automator action index (currentAction + 15) of front workflow to set enabled to true
tell Automator action index (currentAction + 16) of front workflow to set enabled to true
else -- enable it
tell Automator action index (currentAction + 2) of front workflow to set enabled to true
tell Automator action index (currentAction + 3) of front workflow to set enabled to true
tell Automator action index (currentAction + 4) of front workflow to set enabled to true
tell Automator action index (currentAction + 5) of front workflow to set enabled to true
tell Automator action index (currentAction + 6) of front workflow to set enabled to true
tell Automator action index (currentAction + 7) of front workflow to set enabled to true
tell Automator action index (currentAction + 8) of front workflow to set enabled to true
tell Automator action index (currentAction + 9) of front workflow to set enabled to false
tell Automator action index (currentAction + 10) of front workflow to set enabled to false
tell Automator action index (currentAction + 11) of front workflow to set enabled to false
tell Automator action index (currentAction + 12) of front workflow to set enabled to false
tell Automator action index (currentAction + 13) of front workflow to set enabled to false
tell Automator action index (currentAction + 14) of front workflow to set enabled to false
tell Automator action index (currentAction + 15) of front workflow to set enabled to false
tell Automator action index (currentAction + 16) of front workflow to set enabled to false
end if
return input
end run
This is what leads up to the script:
http://cl.ly/image/2D2J3P432q14