Page 1 of 1

Automator Script fails from within Hazel only

PostPosted: Tue Feb 11, 2014 6:08 pm
by musecaptain
Hi

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

Re: Automator Script fails from within Hazel only

PostPosted: Wed Feb 12, 2014 4:13 pm
by Mr_Noodle
Is there a reason why you are using Automator at all? Can't you use Hazel for the first part and Hazel's "Run AppleScript" to run the script?

Re: Automator Script fails from within Hazel only

PostPosted: Wed Feb 12, 2014 5:24 pm
by musecaptain
Mr_Noodle wrote:Is there a reason why you are using Automator at all? Can't you use Hazel for the first part and Hazel's "Run AppleScript" to run the script?


I want to also be able to use the same commands as a service (for right clicking on a file).

Re: Automator Script fails from within Hazel only

PostPosted: Fri Feb 14, 2014 4:20 pm
by Mr_Noodle
Maybe someone else can chime in here but if it's failing as a service too then it goes beyond the support I can give. I suggest focusing on getting it working outside of Hazel before trying to integrate it.