Does Applescript provide a mechanism for me to search for a message by subject; or do I have to write a loop and examine every message "by hand".
The code below generates this error: Mail got an error: Can’t get subject of mailbox.
tell application "Reminders"
set snoozeList to "Snooze"
set notCompleted to reminders in list snoozeList whose completed is false
set numNotCompleted to (count of notCompleted)
repeat with index from 1 to numNotCompleted
set reminderName to name of item index of notCompleted
tell application "Mail"
set theMailbox to mailbox "Snooze" of account "GVSU"
set foundIt to (message in theMailbox whose subject is reminderName)
display dialog read status of message foundIt
end tell
end repeat
end tell
The error message suggests that whose
is being applied to the mailbox and not the messages; but, I can't figure out how to rephrase that line of code.
(For context, I would like to write a script that will iterate over all Reminders and move the linked email from the "Snoozed" folder back to the inbox. First, however, I have to figure out how to get a reference to the linked email.)
(every message in theMailbox whose subject is reminderName)
first message in theMailbox whose...
, though this will throw an error if it can't find a message satisfying the criterion, whereasevery message
will return an empty list.message id
. To retrieve a specific email, it would be much faster to have stored theid
property of the message with or without themessage id
property.message id
is limited to use in awhose
filter clause, e.g.set M to a reference to the inbox's first message whose message id = "..."
. To check:if M exists then...
(slow!).id
gives direct access to a message (so no searching), i.e.set M to a reference to «class mssg» id 74760 in the inbox
, then checking:if M exists then...
is instant!message id
as a property belonging to amessage
class object, which then means you can't referencemessage
class objects by theirid
using regular nomenclature, which should beget message id 74760 in the inbox
...spot the problem ? So you have to use raw syntax to reference themessage
class object, which is«class mssg»
, and then do it in a way so that Script Editor's parser doesn't expand it back into the termmessage
. ]tell app "Mail" to tell the first item in (get selection) to return its properties
Examine the output in detail and that will make things clearer. But to answer your question,74760
is an integer assigned by the Mail app to a specific message (the integer itself will vary from message-to-message). It is held in theid
property. Themessage id
property, however, holds a UUID RFCC822 message ID. Raw syntax was exemplified in the same sentence I used the term.