in applescript

Archive messages with a single keystroke in Mail.app

Aug 2011 Lion update: the script works but is quite slow in Lion (it’s zippy in Snow Leopard). I’m looking for a workaround, but this appears to be a Mail.app bug.

TL;DR version: Archive Mail messages with a single keystroke:

  1. Download this script and Fastscripts (free for up to 10 hotkeys)
  2. Move the script to ~/Library/Scripts/Applications/Mail/
  3. Set your hotkey in Fastscripts (Using a letter key is possible but not recommended. Try another character like `\/=- or an F-Key.)

The script will then move selected message(s) to a folder named “Archive”.

More information:

Existing shortcuts to file messages in Mail.app get you down to two or three keystrokes, but that just isn’t good enough for someone who has tasted the sweet, sweet bliss of single-keystroke archiving in Postbox or Gmail.

In my original reply to this superuser thread, I suggested using an AppleScript to move selected messages to an archive, and triggering the script using a single-key shortcut using Fastscripts. That script is simple and straightforward, but it has a major shortcoming: it leaves you hanging with no next message selected, so you have to manually select your next message. Not ideal.

My new script archives messages with a bit more smarts. Here’s what it does:

  • If a mailbox is in the foreground, the script moves selected messages to the folder named “Archive” and selects the next available message. Boom.

  • But you don’t want to accidentally archive messages whenever you hit your archive key. If the frontmost window isn’t a mailbox, the script will ignore the archiving functions and (optionally) type some text wherever you are. This is useful if you use a single key to trigger the script; without this function, you would never be able to type that key into a mail message because it’s intercepted by FastScripts before getting to the Compose window.

For interested scripters, here were some challenges:

  • Select next message: The solutions I found online select the next message by sequential Message ID, which usually means that it only works if your mailbox is sorted by Date Received. Using visible messages gets messages in the order in which they’re displayed. Watch out, though: if message threading is turned on, the top-level thread item is not selectable. See my workaround in the script.

  • Enter the keystroke that was captured: Merely telling System Events type the character that triggered the script will trigger the script again, resulting in a virtual infinite loop. I used a paste routine to work around this.

That’s it… happy archiving!

22 Mar 2011 update: fixed bug that caused selection to be lost when only the topmost message in a mailbox is selected.

applescripticon.gif

Download: Archive Selected Messages

Write a Comment

Comment

11 Comments

  1. Sorry for asking but what are you talking about? Apple Mail is not Outlook, I don’t see any reason for something like archiving. For what reason. SAo I can’t search my old mails anymore? I have all (and I mean ALL) of my mails since 2001 in Mail and it works just fine. Any explanations?

  2. @Chris @Eric Hadn’t seen Apptivate or the archive plugin. Both look slick, but can they implement shortcuts without using a modifier key?

    @Gudehus My script simply moves selected messages to a folder named “Archive”. It has nothing in common with the Outlook “archive” function, although I see how that could be confusing. I’ll update the post text to clarify.

  3. Anybody have a solution for archiving to different account folders? My situation is that I have 2 IMAP accounts in Mail. Ideally with one keystroke, I could archive personal emails to one folder, and work emails to another.

  4. Cy, the script should handle that as long as you have a folder named “Archive” in each account. It files each message to the archive folder of its own account… hope that helps.

  5. It is the best time to make some plans for the longer term and it’s time to be happy. I have learn this submit and if I could I want to recommend you few fascinating issues or tips. Maybe you could write next articles relating to this article. I desire to learn even more issues approximately it!

  6. список правильных продуктов питанияна сколько кг можно похудеть от зеленого чаядиета при детском ожирениидиеты на которых сидят спортсмены перед соревнованиемкак похудеть что б потом не поправитьсядиета молокосильно похудеть за пять днейцентр снижения веса доктор борменталь г. ярославльдиета при проблемной коже на лице90 дневная диета разхдельного питанияправила подачи сводки в стационаре на питаниеталица каллорийности по кремлевской диетепочему на диете не худеюпохудение убрать бока и животпансионат для похудения пущеномедпрепараты для похудениядиета считать каллориидолжностные обязанности мед.сестры по диетологииаттестация диетсестрысемя льна свойства диета

  7. This is saving me so much time.

    I have five IMAP accounts in Mail, each with an Action folder. When I process my combined inbox, moving emails I want to follow up to the appropriate Action folder is now a single keystroke (courtesy of Alfred). Previously I had to select Move To > [appropriate account ] > Action, which was tedious and slow.

    Thank you!

  8. Looks like it has some wonky behavior in Mountain Lion (10.8) where archiving multiple items simultaneously is not possible (creates an empty message instead) and the focus goes to a seemingly random email after archiving a single message. Any thoughts?