Having gotten rather annoyed with how Yosemite broke the action of the right arrow key to bring me to the first unread message of a conversation, I decided to try out some of the available AppleScript that selects the next unread message.
The most robust version I found was:
try
tell application "Mail"
activate
tell the front message viewer
set unreadMessages to (the messages whose ¬
read status is false) as list
if (count of unreadMessages) is not 0 then
set selected messages to {the first item of unreadMessages}
else
beep
end if
end tell
end tell
on error error_message
beep
display dialog "Error looking for next unread message: " & ¬
return & return & error_message buttons {"OK"} default button 1
end try
The version submitted to this forum by Bruce Philips in 2009 doesn’t seem to work in Mavericks.
http://macscripter.net/viewtopic.php?id=17906
So I decided to bite the bullet and learn AppleScript, and to study the Mail.app dictionary.
I discovered that indeed Yosemite returns the list of unread messages in unsorted form, compared to Mavericks.
I crafted the AppleScript below to show me EXACTLY what was being chosen so that I could confirm all was well:
try
tell application "Mail"
activate
set outStr to ""
set selMessage to null
set unreadMessages to the messages of the front message viewer ¬
whose read status is false
repeat with thisMessage in unreadMessages
if selMessage is null then
set selMessage to thisMessage
else
if (date received of thisMessage) is less than (date received of selMessage) then
set selMessage to thisMessage
end if
end if
set newStr to the subject of thisMessage & ": " & ¬
(date received of thisMessage) & return
set outStr to outStr & newStr
end repeat
display dialog outStr & return & "Selected: " & ¬
the subject of selMessage
set selected messages of the front message viewer to selMessage
end tell
on error error_message
beep
display dialog "Error looking for next unread message: " & ¬
return & return & error_message buttons {"OK"} default button 1
end try
And this works just fine under Maverics, but under Yosemite, NO message is selected.
(Actually there is a failure mode where one is selecting into a conversation that is closed,
but I’ll leave that as question #2 when we get the basic thing working again under Yosemite.)
In the helpful article from this site on using Dictionaries
http://macscripter.net/viewtopic.php?id=24777
We see the bottom line:
So…
Does anyone know how to get Mail.app in Yosemite to actually select a message?
The way that used to work now fails.