Skip to content

Instantly share code, notes, and snippets.

@codahale
Created August 24, 2009 21:25
Show Gist options
  • Save codahale/174219 to your computer and use it in GitHub Desktop.
Save codahale/174219 to your computer and use it in GitHub Desktop.
tell application "Mail"
set selectedMessages to the selection
set mailboxMap to {{accountName:"Work", archive:"All Mail"}, {accountName:"Gmail", archive:"All Mail"}}
repeat with mapItem in mailboxMap
set archiveMailbox to the mailbox (archive of mapItem) of account (accountName of mapItem)
set messagesToMove to {}
repeat with msg in selectedMessages
if name of the mailbox of msg is "INBOX" then
if name of the account of the mailbox of msg is (accountName of mapItem) then
set read status of msg to true
set messagesToMove to messagesToMove & {msg}
end if
end if
end repeat
if messagesToMove ≠ {} then
move messagesToMove to archiveMailbox
end if
end repeat
end tell
tell application "Mail" to activate
tell application "System Events"
tell process "Mail"
tell menu bar 1
click menu bar item "Message"'s menu "Message"'s ¬
menu item "Reply All"
end tell
delay 0.5
key code 117 -- Forward Delete
key code 125 -- down arrow
key code 117
key code 125 using command down -- down arrow
key code 126 -- up arrow
key code 126
key code 126
key code 126
key code 36 -- Return
key code 36 -- Return
key code 126
end tell
end tell
tell application "Mail" to activate
tell application "System Events"
tell process "Mail"
tell menu bar 1
click menu bar item "Message"'s menu "Message"'s ¬
menu item "Reply"
end tell
delay 0.5
key code 117 -- Forward Delete
key code 125 -- down arrow
key code 117
key code 125 using command down -- down arrow
key code 126 -- up arrow
key code 126
key code 126
key code 126
key code 36 -- Return
key code 36 -- Return
key code 126
end tell
end tell
tell application "Mail"
set selectedMessages to the selection
set mailboxMap to {{accountName:"Work", archive:"Spam"}, {accountName:"Gmail", archive:"Spam"}}
repeat with mapItem in mailboxMap
set archiveMailbox to the mailbox (archive of mapItem) of account (accountName of mapItem)
set messagesToMove to {}
repeat with msg in selectedMessages
if name of the mailbox of msg is "INBOX" then
if name of the account of the mailbox of msg is (accountName of mapItem) then
set read status of msg to true
set messagesToMove to messagesToMove & {msg}
end if
end if
end repeat
if messagesToMove ≠ {} then
move messagesToMove to archiveMailbox
end if
end repeat
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment