I am trying to develop (well, actually modify) a script to provide navigation in an Apple Mail mailbox.
When a message window is open, Mail does not provide a means to move to the next message without doing this little dance:
______________________________________________________________________
Hey Dave,
Yes. This is a horrible, glaring deficiency in Mail. Every sensible mail client has the ability to go-to the next message, the previous message, the next unread message, or the previous unread message.
Unfortunately given threading and sorting I don't see a way to reliably do it with Applescript.
I fooled with the attached methods without reliable success with Mountain Lion's Mail (6.2). You can see if either method bears fruit with Snow Leopard.
-- Best Regards, Chris
-------------------------------------------------------------------------------------------
try
tell application "Mail"
# close front window
tell (some message viewer whose index is 1) set _mailbox to item 1 of (get selected mailboxes) set _msg to item 1 of (get selected messages)
set _date to date sent of _msg set _id to id of _msg set mList to {(last message of _mailbox whose date sent > _date)}
set selected messages to mList
end tell
end tell
on error e number n set e to e & return & return & "Num: " & n tell me to set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK" if button returned of dDlg = "Copy" then set the clipboard to e end try
-------------------------------------------------------------------------------------------
On Mountain Lion selList fails to reliably set the selected messages, and the 2nd set selected messages to selList throws an error.
-------------------------------------------------------------------------------------------
try
tell application "Mail"
tell (some message viewer whose index is 1) set mbox to item 1 of (get selected mailboxes) set msg to item 1 of (get selected messages)
set _flag to false
repeat with i in (reverse of (get messages of mbox))
set _temp to (contents of i)
if _flag = true then set nextMsg to _temp exit repeat end if
if _temp = msg then set _flag to true end if
end repeat
set selList to {nextMsg} selList set selected messages to selList selList open nextMsg selList set selected messages to selList ## ERRORS HERE WITH EMPTY LIST — BUG MAYBE ## selList
end tell
end tell
on error e number n set e to e & return & return & "Num: " & n tell me to set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK" if button returned of dDlg = "Copy" then set the clipboard to e end try
------------------------------------------------------------------------------------------- |