A while back, we published a short tutorial showing how to archive mail with a keyboard shortcut. This tip in itself is a huge timesaver, but one reader wanted to take things a little further and asked how to use a keyboard shortcut to move messages to specific mailboxes and not only the archive.
After better understanding the requirements, the answer was obvious to me — use Keyboard Maestro, a premiere Mac automation tool. Keyboard Maestro may seem daunting at first, but once you get a grasp for its mechanics, bending your Mac to your will becomes child’s play.
Creating a Palette
First you need to create a palette to hold all your destination mailboxes. This can be achieved easily by grouping all your macros together.
- Create a new Macro group by pressing ⇧⌘N (or clicking the bottom left +) and give it a name;
- Click Available in all applications and change to Available in the following applications:, then choose Mail.app. This will ensure the palette only displays when Mail.app is active;
- Click Always Activated and choose Show a palette for one action when:. Finally assign the desired keyboard shortcut (I went with ⇧⌘E).
Your new macro group ready for macros.
Now that you have your macro group created, it’s time to populate it with macros.
- Press ⌘N (or click the + in the bottom middle) and give it a name. Note that the name you choose is important since Keyboard Maestro will sort your macros in alphabetical order. Fortunately, there is a small trick that will allow you to manually sort your actions. By simply prefixing the name with 2 digits and a closing bracket such as 00), Keyboard Maestro will hide the numbers, but still use them to sort your macros.
- Click New Trigger and add a Hot key trigger. Since it’s possible to click on a macro inside the palette, this step is optional, however I strongly advise it.
- Click New Action, from the panel that appears, click on Execute and then double click Execute and AppleScript;
- Leave Execute Text Script as is and change ignore results to display results briefly.
- Finally paste in the following script. Remember to adapt it to suit your particular needs: on line 7, change App Testing to your desired mailbox and iCloud to your account name (Gmail, Personal, Work etc.).
Tip: If you’re unsure what your accounts are named, simply open Script Editor and paste in
tell application "Mail" to get accounts. This will give you a list of accounts. Similarly,
tell application "Mail" to get mailboxes of account "iCloud" will give you a list of all mailboxes in a specified account.
Now the first macro is complete, duplicate it for as many mailboxes as desired (select the macro and press **⌘D**), remembering of course to change the appropriate values such as the hot key trigger, macro name and AppleScript.
Why Stop There
There’s no reason to stop there though. Why not take this time to create a few macros that’ll allow you to jump to specific mailboxes too.
- Duplicate one of the above macros and change its name to reflect the new action: Go to mailbox X (don’t forget to change the hot key trigger too);
- In the Execute an AppleScript action, click display results briefly and change it back to ignore results;
- Now, replace the previous script with the one below, remembering to change the appropriate values;
If all went well, you should now have a macro palette which can be triggered when Mail.app is active. Trigger it, then either click the desired action or press its hotkey if you assigned one.
The final output. Create empty macros with just a name (or spaces) to create the seperators seen above.
As you can see, Keyboard Maestro is immensely powerful and easy to use once you’re comfortable with it. If you don’t already own Keyboard Maestro, I strongly advise you download the 30 day trial and see where else you can integrate it.