Skip to content

Instantly share code, notes, and snippets.

@benzado
Created July 25, 2011 21:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benzado/1105322 to your computer and use it in GitHub Desktop.
Save benzado/1105322 to your computer and use it in GitHub Desktop.
Archive Messages (AppleScript for Mac Mail)
(*
Moves selected messages into an archive folder. I use FastScripts to bind this to Shift-Cmd-A.
For Gmail accounts, moves messages into "[Gmail]/All Mail"; for all other accounts, looks for a mailbox named "Archive".
Tested with Mail 4.5 (Mac OS X 10.6 Snow Leopard).
*)
tell application "Mail"
tell front message viewer
if (count of selected messages) is 0 then
display alert ¬
"No messages selected." message ¬
"Select the message or messages you want to archive, then invoke the command again." as warning
return
end if
set _messages to selected messages
end tell
set _group to {}
set _account to null
set _mailbox to null
repeat with _msg in _messages
set _msg_account to account of mailbox of _msg
if (_account is _msg_account) then
set _group to _group & {_msg}
else
if _mailbox is not null then
log "Moving messages"
move _group to _mailbox
end if
set _group to {_msg}
set _account to _msg_account
if exists mailbox "[Gmail]" of _account then
set _mailbox to mailbox "All Mail" of mailbox "[Gmail]" of _account
else if exists mailbox "Archive" of _account then
set _mailbox to mailbox "Archive" of _account
else
display alert "No archive mailbox." message "Create a mailbox named \"Archive\" under account \"" & name of _account & "\" to store archived messages." as warning
return
end if
end if
end repeat
log "Moving messages (final)"
move _group to _mailbox
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment