Here a short explanation of your error, or âhow to find out how to get the Received Timeâ:
When I said that the name of a variable doesnât matter, I literally meant âvariableâ. The date received
is not a variable, itâs a property of message
and it is part of Mailâs scripting dictionary.
You cannot simply change the names of these things. (Well, you can, but this would mean working by trial and error.) To see the scripting dictionary of an app, do the following:
- Launch Script Editor (/Applications/Utilities/Script Editor.app)
- Go to File > Open DictionaryâŚ
- Choose the Mail app from the list.
- In the toolbar of the now open window make sure that âAppleScriptâ is selected as language.
- You now see the AppleScript dictionary of Mail
- Go through the dictionary and look for the thing of interest, or use the search field.
- To stay with the example: If you type âreceivedâ into the search field you will only get one hit: âdate receivedâ. This tells us that a property âtime receivedâ doesnât exist in Mailâs dictionary.
That means that we cannot change date received
to âtime receivedâ, because Mail can not understand that. (Itâs not part of its dictionary.)
OK, fine. But how to get the Time?
Common sense tells us that it is very unlikely that there would be no way to get the Received Time. And, since date received
seems to be the only thing related to âreceivedâ, we should suspect now that the Time is somehow part of that date received
property.
Since we already had a working script line with date received
, things are easy here:
The date was obtained with date string of (get date received of theMsg)
. The âofâ tells us that date string
must be a part of date received
, and since âdateâ is a specifier of âstringâ we can assume that there must be other strings besides the date string
.[1]
Unfortunately Script Editorâs dictionary viewer gives us no hint here[2], but in this case a trial and error approach seems promising: VoilĂ , time string of (get date received of theMsg)
will work as expected.
I hope this helps a bit for future adventures
[1] One of the cases where the human-language-like syntax of AppleScript is beneficialâŚ
[2] This is because time string
is a property of the date
class which is part of the AppleScript types suite. I have found no way to display this in Script Editorâs dictionary viewer. One more case where Script Debugger makes life easier: if you type âtimeâ in Script Debuggerâs dictionary viewerâs search field you get âtime stringâ as hit #2.