0

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.)

  • 1
    Try: (every message in theMailbox whose subject is reminderName) – Patrick Wynne Dec 28 '18 at 1:02
  • Yes. Well, almost. Your suggestion returned a list. When I took the first element of that list, everything worked as expected. Thanks. – Zack Dec 28 '18 at 1:46
  • 1
    In that case, first message in theMailbox whose..., though this will throw an error if it can't find a message satisfying the criterion, whereas every message will return an empty list. – CJK Dec 28 '18 at 3:33

You must log in to answer this question.

Browse other questions tagged .