I have an AppleScript that will create a new note with a link to an email, which works fine.
I decided to “improve” it by adding the date the email was received to a User Attribute “$Received” of type “Date".
The script then promptly fails with this error:
I verified that $Received is of type Date:
ChatGPT suggested using “Evaluate” within the AppleScript, which appears below. The script runs without error, but $Received remains the default value “Never”.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
--set entryTitle to text returned of (display dialog "Entry Title?" default answer "")
set entryText to text returned of (display dialog "Entry Text?" default answer "")
tell application "Mail"
-- if not it is running then activate
if not (get selection) is {} then
set theMsg to item 1 of (get selection)
else
return
end if
tell theMsg
set {msgID} to {message id}
set msgURL to "message://%3C" & msgID & "%3E"
set senderText to sender of theMsg
set subjectText to subject of theMsg
set receivedDate to date received of theMsg
set receivedDateText to short date string of receivedDate & " " & time string of receivedDate
end tell
end tell
tell application id "Cere"
activate
set this_moment to (the current date)
set nmMonth to (month of this_moment) as string
set nmYear to (year of this_moment) as string
set thePath to "Captain's Log/" & nmYear & "/" & nmMonth & " " & nmYear & "/" & date string of this_moment
tell document "Captain's Log.tbx" -- suffix .tbx required on my machine
-- this is how to specify a note down in the hierarchy:
set theContainer to find note in it with path thePath
set newNote to make new note at theContainer
tell newNote
--if entryTitle is not missing value then set value of attribute "Name" to entryTitle
set value of attribute "Text" to entryText
set value of attribute "Prototype" to "p_Email"
set value of attribute "MailURL" to msgURL
set value of attribute "Badge" to "mail-open"
set value of attribute "Name" to subjectText
set value of attribute "Sender" to senderText
evaluate with "$Received=" & quoted form of receivedDateText & ";"
end tell
end tell
end tell
The relevant date information is accurately captured within the AppleScript itself:

(Screencap from Script Debugger)
ChatGPT has gone on to suggest a very elaborate fix that I don’t think will work. I figure it has to be something simple, so reaching out to the Forum for any insight or solutions. I need $Received to be of type Date so the notes are sorted properly.
Thanks in advance.

