Page 1 of 1

Returning Values to Hazel Using hazelOutputAttributes

PostPosted: Wed Feb 01, 2017 3:32 am
by theodrak
Hi,
Ive just discovered Hazel and think its amazing. Please forgive me, but I am very new to both Hazel and Apple script and am trying to write a very simple script (external) that returns a value (File Name) back to Hazel to be used later on when renaming the file. In this instance "New Filename.pdf. See eg code below.

Code: Select all
on hazelMatchFile(theFile, inputAttributes)
   
   return {hazelOutputAttributes:{"New Filename.pdf"}}
   
end hazelMatchFile


However this simple script throws an exception

Invalid AppleScript return value: <NSAppleEventDescriptor: { 'usrf':[ 'utxt'("hazelOutputAttributes"), [ 'utxt'("New Filename.pdf") ] ] }>.


I was wondering if there is a simple example of an external Applescript returning values which I can reference? Ive tried searching the forum to no avail.

Re: Returning Values to Hazel Using hazelOutputAttributes

PostPosted: Wed Feb 01, 2017 12:03 pm
by Mr_Noodle
You are missing "hazelPassesScript" which is required for a match script (as opposed to action). Try adding that or moving the script to the action section.

Re: Returning Values to Hazel Using hazelOutputAttributes

PostPosted: Wed Feb 01, 2017 3:50 pm
by theodrak
Thanks Mr_Noodle thats worked. Took me a little while but got there.

Code: Select all
on hazelMatchFile(theFile, inputAttributes)
   
   return {hazelPassesScript:true, hazelOutputAttributes:{"New Filename.pdf"}}
   
end hazelMatchFile