On May 20, 2009, at 8:07 PM, Jim Krenz wrote:
I am trying to create a script that will move to the next mailbox with unread messages, and select the first unread message. I haven't been successful (I'm still a AppleScript beginner). Here is what I have thus far. Any suggestions are welcome.
tell application "Mail" to try
tell message viewer 1 to set selected messages to {first message of beginning of (get mailbox whose unread count > 0) whose read status is false}
activate
on error
beep
end try
Here's something you might want to experiment with (10.5.7) ...
tell application "Mail"
activate
set frontViewer to (message viewer 1)
set allMailboxes to mailboxes as list -- does not need open message viewer
repeat with mbox in allMailboxes
try
if (count messages of mbox) > 0 then
set selected mailboxes of frontViewer to {mbox}
set msg to first message of frontViewer
set selected messages of frontViewer to {msg} -- does NOT always hilite a message
display dialog (subject of msg) as text --*****************diagnostic
delay 1
end if
on error errText number errNr
"Error = " & errNr & return & errText
display dialog the result default button 2
end try
end repeat
end tell
tell application "Finder" to beep
I was surprised to find that 'set selected messages ...' does not always select something and I still cannot figure out why. I try to avoid "one liners", they often create errors. Or make errors hard to find.
Even if the message is not selected, 'msg' seems to be valid.