1

I've had a script that used to work perfectly to check if I've received an email with a certain subject (below):

tell application "Mail"
check for new mail
repeat until (background activity count) = 0
    delay 0.5
end repeat
try
    return subject of (first message whose read status is false and subject contains "New newsletter ordered by")
end try
end tell

Now AppleScript refuses to read emails' subjects. Any ideas why? I'm assuming there's been an update that's broken it but I can't find any information on that.

t56k
  • 6,769
  • 9
  • 52
  • 115
  • Does this script still work for you? When I try to use `background activity count` I get an error message, see https://stackoverflow.com/questions/74249201/applescript-mail-apps-property-background-activity-count-is-broken – d-b Oct 30 '22 at 08:09

3 Answers3

0

Try

return subject of (first message of inbox whose read status is false and subject contains "New newsletter ordered by")
adayzdone
  • 11,120
  • 2
  • 20
  • 37
0

I have a 10.7.4 computer and get an error when there is no message with those properties are found. If there is an unread message containing that subject, the script (the one that says "first message of inbox") works fine.

Sojourner
  • 66
  • 1
0

This seems to work for me, I first had to select the first message and then I could get the subject:

tell application "Mail"
   set theInbox to inbox
   set theMessage to first message of theInbox whose read status is false
   tell front message viewer to set selected messages to {theMessage}
   set theMessages to (get selection)
   repeat with theMessage in theMessages
       get subject of theMessage as string
   end repeat
end tell
thiesdiggity
  • 1,897
  • 2
  • 18
  • 27