Automator Script fails from within Hazel only

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

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
musecaptain
 
Posts: 27
Joined: Tue Oct 08, 2013 2:38 pm

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?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

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).
musecaptain
 
Posts: 27
Joined: Tue Oct 08, 2013 2:38 pm

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.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support