AppleScript error

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

Moderator: Mr_Noodle

AppleScript error Mon May 29, 2023 7:51 am • by Lachlan Williams
I have a Hazel rule that analyses PDF files and generates tokens found in Contents --> Contain Match to find number strings (eg: "333.00" or "59.95").

The rule which passes tokens corresponding to those numbers into an AppleScript and I want to get it to pass back a calculated result to use as a token, but it's not working.

Code: Select all
on hazelProcessFile(theFile, inputAttributes)
   
   #Set variables based in input attributes from Hazel
   set theAmount to item 1 of inputAttributes as text
   set theWaterCharges to item 2 of inputAttributes as text
   
   set CouncilCharges to (convNum(theAmount) - convNum(theWaterCharges)) as number
   return {hazelStop:false, hazelSwitchFile:myFile, hazelOutputAttributes:CouncilCharges}
   
end hazelProcessFile

on convNum(x as text)   
   return x as number   
end convNum

on convStr(y as number)
   return y as text
end convStr


I know the Hazel rule is passing parameters correctly (tested with another script) but I can't get the above script to pass back the result to Hazel. Must be something to do with the last line of code to return the result? I've confirmed the script gets at least that far by adding a "beep" command just before it (I couldn't figure out another way to debug and see how far it gets - would love tips on smarter ways to do this!)
Lachlan Williams
 
Posts: 13
Joined: Fri Jun 11, 2021 4:06 am

Re: AppleScript error Mon May 29, 2023 9:03 am • by Mr_Noodle
The value for 'hazelOutputAttributes' is a list, not a single value. The order of the list needs to match the order you specified the output attributes in Hazel's interface (not that it matters here since you only have one item).
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: AppleScript error Sat Jun 03, 2023 12:49 am • by Lachlan Williams
Mr_Noodle wrote:The value for 'hazelOutputAttributes' is a list, not a single value. The order of the list needs to match the order you specified the output attributes in Hazel's interface (not that it matters here since you only have one item).


OK thanks...I'm new to AppleScript, so does that mean I just need to add extra brackets around the 'CouncilCharges' variable like this:
Code: Select all
return {hazelStop:false, hazelSwitchFile:myFile, hazelOutputAttributes:{CouncilCharges}}


or do I remove the hazelStop and hazelSwitchFile values and just have it like this:
Code: Select all
return hazelOutputAttributes:{CouncilCharges}


Sorry, the documentation wasn't too clear on this for me.
Lachlan Williams
 
Posts: 13
Joined: Fri Jun 11, 2021 4:06 am

Re: AppleScript error Mon Jun 05, 2023 8:34 am • by Mr_Noodle
The first one should be correct.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support

cron