Macos – Shortcut for moving an email to another folder in Mail.app

apple-mailapplescriptkeyboard shortcutsmacososx lion

How could I setup a keyboard shortcut for Mail.app in OSX Lion so an email in the inbox, which is still unread, when I use this shortcut is moved automatically to some other previously defined folder?

Best Answer

Open up Automator and create a new Service. Set it to receive "no input", then drag Run AppleScript from the left pane to the right.

Paste the following script — note that you have to change my-account to the actual name of the account where your source and destination mailboxes are*. Also, change destination to the name of the destination mailbox under the specified account.

tell application "Mail"
    repeat with theMessage in {messages in mailbox "INBOX" of account "my-account" where read status is false}
        set theMailbox to mailbox "destination" of account "my-account"
        move theMessage to theMailbox
    end repeat
end tell

If you only want it to affect the general inbox:

tell application "Mail"
    repeat with theMessage in {messages in inbox where read status is false}
        set theMailbox to mailbox "destination" of account "my-account"
        move theMessage to theMailbox
    end repeat
end tell

Save this service. Then, under System Preferences » Keyboard » Keyboard Shortcuts, create a new keyboard shortcut for this service.

And you're done.


* You can find out the account name by going to Mail's preferences, then under Accounts, see the Description line.

Related Question