hazelOutputAttribute not returning a value

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

Moderator: Mr_Noodle

hazelOutputAttribute not returning a value Wed Oct 31, 2018 12:27 pm • by Krzystofczyk
In processing one of my scanned statements as a PDF, there is no statement date. So I want to get it from user input via AppleScript and a dialog box. After struggling to realize that "hazelOutputAttributes" only works for multiple outputs, and that I need to use hazelOutputAttribute (no "S") to get it to run without an error, here's my code:

Code: Select all
-- Need to get the Statement Date from the user in yyyy-mm-dd format

-- Current Date for default value
set currentYear to year of (current date) as string
set monthAsNum to month of (current date) as integer
set currentMonth to monthAsNum as string
set currentDay to day of (current date) as string
set curDate to (currentYear & "-" & currentMonth & "-" & currentDay) as string

tell application "System Events"
   set statementDate to text returned of (display dialog "What is the statement date?" default answer curDate buttons "OK")
end tell

return {hazelPassesScript:true, hazelOutputAttribute:statementDate}


This runs, provides me with a dialog box (and a default date of today), and does everything except return a value. I've defined a custom attribute StatementDate as a text attribute in the names of custom attributes the script exports. When I run this code from Script Editor, I see the result:

Code: Select all
{hazelPassesScript:true, hazelOutputAttribute:"2018-10-31"}


But in Hazel, the StatementDate is blank. I have added a condition to check that it is not blank, and that condition always fails. I'm fairly new to AppleScript and Hazel, so this may be easy, but I can't seem to find any entry in the forum explaining this. Any help would be much appreciated.

Thanks,

Carl
Krzystofczyk
 
Posts: 2
Joined: Wed Oct 31, 2018 12:17 pm

It's actually hazelOutputAttributes (with an "s"). The problem is that you need to specify a list, not a single value, as there may be multiple. So something like:
Code: Select all
{hazelPassesScript:true, hazelOutputAttributes: {"2018-10-31"} }
Mr_Noodle
Site Admin
 
Posts: 11236
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle wrote:It's actually hazelOutputAttributes (with an "s"). The problem is that you need to specify a list, not a single value, as there may be multiple. So something like:
Code: Select all
{hazelPassesScript:true, hazelOutputAttributes: {"2018-10-31"} }


Well, that does indeed solve the problem! I was confused by the Hazel Help that showed using parenthesis instead of braces, which resulted for me in an error condition:

Code: Select all
hazelOutputAttributes:  A list (AppleScript) or array (JavaScript) of values for the custom attributes this script exports. The values must be in the order as you specify in the interface. See the section below on  Custom Attributes . Here’s an example in AppleScript:


-- your supporting code here

set color to "blue"

set flavor to "raspberry"

return {hazelPassesScript:true, hazelOutputAttributes:(color,flavor)}


Now that I know the syntax, I'm up and running. Thanks!
Krzystofczyk
 
Posts: 2
Joined: Wed Oct 31, 2018 12:17 pm


Return to Support

cron