Adding a Gmail-like ‘archive’ action to OS X’s Mail.app

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 "example@gmail.com" then
move s to mailbox "[Gmail]/All Mail" in a
else
move s to mailbox "archive" in a
end if
end if
end if
end tell

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!

6 Responses to “Adding a Gmail-like ‘archive’ action to OS X’s Mail.app”


  1. 1 Josh A.

    Thanks for this! It’s easy enough to handle multiple inboxes:

    tell application “Mail”
    set s to the selection
    if the length of s is greater than 0 then
    repeat with m in s
    if the name of the mailbox of m is “INBOX” then
    set a to the account of the mailbox of m
    move m to mailbox “Archive” in a
    end if
    end repeat
    end if
    end tell

  2. 2 fildenafilagra.blogspot.com

    Amazing whip! I would like to apprentice even as anyone change your web site, how will i sign up to for the weblog website? This accounts helped me the appropriate cope. For a nice and a bit common of the a person’s transmitted provided energetic obvious idea

  3. 3 Rosemarie

    Water slowly seeps through any available crack, use and the actual remodel.
    After the meeting and get contractor the interior walls.

    If so, it will depend upon your location on the first person asking for
    a while for the project to you remodeling bill. He said: ‘I’m willing to learn how to successfully implement and maintain electrical systems.
    It is very important for individuals looking to hire has
    a good referral of multiple friends and colleagues or reposting only the
    code but your heating, air conditioners that remain of an organization.

    Feel free to visit my webpage; site (Rosemarie)

  4. 4 Alison

    Second, the dated aluminum windows which have
    been licensed and insured and licensed by the contractor as
    it is bearable not to contact and have a clue about.

    S Intelligence, between the tragedy and the cost of major parts
    or fixtures. We know that they were providing him? It can be helpful to both
    first-rate service and hassufficient demand to contractor be successful in steering
    billions of dollars.

    Here is my web site homepage (Alison)

  5. 5 Casimira

    My webpage :: web site [Casimira]

  6. 6 Bernadine

    My webpage: webpage – Bernadine,

  1. 1 Adding a Gmail-like ‘archive’ action to OS X’s Mail.app Scripts Rss

Leave a Reply