Edit 22/09/2009: Of course Google has to go and change things around two days after I post this script. Now, for Gmail accounts if the script doesn’t work with “[Gmail]/All Mail” being the account name, you’ll want to try “[Google Mail]/All Mail”.
I used to just leave mail in my inbox and let it pile up until the counter read “thousands.” I would occasionally tag messages that were very specific to a project I was actively working on, but that was about it. But with Gmail’s highly accessible Archive button and awesome and, at the time, revolutionary and unheard of search capabilities, hitting that Archive button didn’t seem like such a bad idea.
Now, things in my inbox are purely things that need my attention, either now or months from now, and the count hovers around 15-30.
However, I recently switched to Mail.app on OS X, and while it’s a simple enough task to create an ‘archive’ mailbox to put mail messages in, to do so requires a time-consuming drag operation, since there’s no button that can do this for you. When you add enough mail accounts (I for one actively monitor 6 accounts), the list of mailboxes become long enough that the drag operation is compounded by a scroll operation.
To this end, I’ve written a quick Applescript (adapted from the one John Gruber wrote over on Daring Fireball which works a bit differently) that will take selected items and shove them in a mailbox entitled ‘archive’, exactly as Gmail does. You’ll have to hack it up a bit in an intelligent way, since there’s some code in there that is specific to my mailboxes. If you monitor any Gmail accounts within Mail.app, you’ll want to copy the special-casing I did for the fictional Gmail account below.
set _description to "Move selected item into the archive mailbox for the current account. This action is not undoable."
tell application "Mail"
set s to the selection
if the length of s is greater than 0 then
set m to item 1 of s
if the name of the mailbox of m is "INBOX" then
set a to the account of the mailbox of m
if a is account "email@example.com" then
move s to mailbox "[Gmail]/All Mail" in a
move s to mailbox "archive" in a
The only major limitation of the code is that it assumes you select mail only from a single account at a time. If you view inboxes from multiple accounts at a time, then leave a note in the comments below and I’ll be more motivated to fix it.
Unfortunately, Mail.app won’t let you add Applescripts to the toolbar as buttons, so the only way you’ll be able to activate this handily is by enabling the scripts menu at all times (you’ll find the option in the Preferences dialog of Applescript Editor), and assigning a shortcut to it via the Keyboard System Preferences pane. This is a bit less than ideal since the script takes a second to kick in with this method, but it’s what we’ve got.
Maybe someday I’ll turn this into a proper plugin.
In closing, I’d like to simply sum up my thoughts about AppleScript with a short quote from Chris Metcalf:
I don’t want to “say” shit to you applescript, I just want you to do what I want!