Created
December 23, 2008 03:21
-
-
Save rentzsch/39241 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "Mail" | |
set nextSelectedMessageID to missing value | |
set selectedMessages to the selection | |
if (count of selectedMessages) = 1 then | |
set selectedMessageID to id of item 1 of selectedMessages | |
-- Find the selected message's position in the list. | |
set selectedMessageIndex to missing value | |
set msgList to every message of message viewer 1 | |
set msgCount to count of msgList | |
repeat with msgIndex from 1 to msgCount | |
if id of item msgIndex of msgList = selectedMessageID then | |
set selectedMessageIndex to msgIndex | |
exit repeat | |
end if | |
end repeat | |
if selectedMessageIndex = 1 then | |
-- On the "last" msg: select the one previous | |
set nextSelectedMessageID to id of item 2 of msgList | |
else | |
set nextSelectedMessageID to id of item (selectedMessageIndex - 1) of msgList | |
end if | |
else | |
-- TODO handle multiple selection. Somewhat thorny. | |
end if | |
repeat with selectedMessage in selectedMessages | |
set the mailbox of selectedMessage to mailbox "Read" | |
end repeat | |
if nextSelectedMessageID is not missing value then | |
set x to item 1 of (every message of message viewer 1 whose id is nextSelectedMessageID) | |
set selected messages of message viewer 1 to {x} | |
end if | |
end tell | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment