Passing a Hardcoded Text value from Hazel to a Script

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

Moderator: Mr_Noodle

Hope you can help me out.

Is there a was to set a variable/token to a set Value which then can be used as an input variable into a script which is run without matching?

Context:
I have a generic applescript that accepts 8 variables from Hazel. These variables are then manipulated within the script which then returns a text value for Hazel to use later on.

Example of the script: (Please note this is a stripped down version of the logic for purposes of this thread.)
Code: Select all
on hazelMatchFile(theFile, inputAttributes)
   
   set textCompanyName to item 1 of inputAttributes
   set dateReceiptDate to item 2 of inputAttributes
   set textVenueCode to item 3 of inputAttributes
   set textAccountCode to item 4 of inputAttributes
   set textTaxType to item 5 of inputAttributes
   set textInvoiceTotal to item 6 of inputAttributes
   set textCurrency to item 7 of inputAttributes
   set textInvoiceNumber to item 8 of inputAttributes
   
   
   -- Reformat Date to YYYYMMDD
   set yReceiptDate to text -4 thru -1 of ("0000" & (year of dateReceiptDate))
   set mReceiptDate to text -2 thru -1 of ("00" & ((month of dateReceiptDate) as integer))
   set dReceiptDate to text -2 thru -1 of ("00" & (day of dateReceiptDate))
   set textReceiptDate to yReceiptDate & mReceiptDate & dReceiptDate
   
   
   -- Concatenate File Name
   set newFilename to textCompanyName & " - " & textReceiptDate & " - " & textVenueCode & " - " & textAccountCode & " - " & textCurrency & " - " & "Inv " & textInvoiceNumber & ".pdf"
   
   
   -- Return Values to Script
   return {hazelPassesScript:true, hazelOutputAttributes:{newFilename}}
   
end hazelMatchFile

In the code above I would like Hazel to pass through the Value of "CONS" to item 4 of inputAttributes. However this value of "CONS" is not extracted as a match on any content/name etc.

I would Simply like to set/hardcode the value of "CONS" into the inputAttribute of the script. (Note the reason why I dont hard code this in the script is that some rules will pass in different values eg "TRVL"

I have tried to create a Dummy Varable that "Does Not match a Textual Value eg
"Extension" "do not match" *AccountCode
where *AccountCode is Trying to match on the Value "CONS"
This passes (as the file is a PDF an there is no match on the extension being CONS)

I then Pass this variable (*AccountCode) into the AppleScript above in item 4 of inputAttributes from Hazel.

However it unfortunately passes "missing value" into item 4

Is there anyway of setting a hardcoded text string to the variable?

Theo
theodrak
 
Posts: 3
Joined: Fri Jan 20, 2017 2:37 am

No way to do that. Hardcoding it in the script is the only way to do that now.
Mr_Noodle
Site Admin
 
Posts: 11324
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Just wanted to register my request for such a feature to be implemented in Hazel. I'm using an embedded JavaScript which takes Custom Text matches in my Hazel rule, and passing each matched token to an external Python script that uses the Google Sheets API to write the information parsed from the Hazel rule into a new row in a Google Sheet.

However, there's one field in the passed arguments that isn't part of the parsed Custom Text data from Hazel. It would be much easier to manage if I could just use the same JavaScript file in Hazel, and then specify the "hardcoded" attribute in the Custom Attributes panel for the script.
melorama
 
Posts: 7
Joined: Tue May 05, 2009 10:25 pm


Return to Support