Feb 23, '10 07:30:01AM • Contributed by: hibbelig
When you hit 'A' in Thunderbird, it archives each message in a folder based on the date of the message, e.g. INBOX/Archives/2010 for messages from this year. The following AppleScript also does this in Mail. (The script will also mark archived messages as read -- Thunderbird's 'A' key does not do that.)
Copy and paste the following into AppleScript Editor:
on run
tell application "Mail"
set selectedMessages to selection
repeat with selectedMessage in selectedMessages
set msgDate to date sent of selectedMessage
set msgYear to (year of msgDate) as string
set mbox to mailbox of selectedMessage
set acct to account of mbox
set archivePath to "Archives/" & msgYear
try
set archiveMbox to mailbox archivePath
on error theError
make new mailbox with properties {name:archivePath}
set archiveMbox to mailbox archivePath
end try
set read status of selectedMessage to true
move selectedMessage to archiveMbox
end repeat
set nextBox to mailbox of last item of selectedMessages
set nextList to messages of nextBox whose deleted status is false
set nextMsg to my findNext(selectedMessages, nextList)
set message viewer 1's selected messages to {nextMsg}
end tell
end run
on findNext(selectedMessages, allMessages)
set len to count of allMessages
set idx to 1
repeat while idx ≤ len
set candidate to item idx of allMessages
if selectedMessages contains {candidate} then exit repeat
set idx to idx + 1
end repeat
if idx > 1 then
return item (idx - 1) of allMessages
else
return last item of allMessages
end if
end findNextProblem: this does not always select the right message after archiving. If you have any ideas about that, please share.
[robg adds: This should work in both 10.5 and 10.6; I tested it in 10.5 (where it worked perfectly), and the author refers to AppleScript Editor, which is the new name for Script Editor in 10.6.]
