Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

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.

share|improve this answer
    
thanks a lot! the only problem I get is "Mail got an error: Can’t get mailbox "Inbox" of account "MYUSER".". And I checked that the description is correct, any hint? –  flow Apr 25 '12 at 11:39
    
ok, I solved that. Now I see that only recognizes folders that are not "on my mac" (so for me it is useless), and then if I select to move it to, for instance, "Draft" folders, then I get the error "Mail got an error: Can’t make {} into type specifier.". thanks a lot! –  flow Apr 25 '12 at 14:01
    
Both examples work for me. Can you post the script you're currently using and the folders you want to move from/to? I can't guess why it fails.. –  slhck Apr 25 '12 at 15:22
    
@flow What does AppleScript Editor show in the output pane when you run tell application "Mail" to accounts? –  Daniel Beck Apr 27 '12 at 5:14
    
I get: syntax error: Mail got an error: Can’t get mailbox "Personal" of account "this_is_my_account". –  flow Apr 27 '12 at 8:49

You can use the Automator solution for making a Service with the following chunk of AppleScript, which will ask you where you want to move the selected message(s).

use Mail : application "Mail"
use scripting additions

on findMailBox for partialName
    --display dialog "Looking for mailbox with text " & partialName
    set allMailBoxes to mailboxes of account "Apple"
    repeat with m in allMailBoxes
        if ((offset of partialName in (name of m as string)) ≠ 0) then
            return m
        end if
    end repeat
end findMailBox

display dialog "Destination: " default answer ""
set destinationName to the text returned of the result

set moveTo to findMailBox for destinationName

set theSelection to selection of Mail
repeat with m in theSelection
    --display dialog "will move message " & (id of m as string) & " to mailbox " & (name of moveTo as string)
    move m to moveTo
end repeat
share|improve this answer

No longer works works in Mavericks (Mail 7.3)

This does:


tell application "Mail"
    repeat with theMessage in (every message of (mailbox "current" of account "my-account"))
        set mailbox of theMessage to mailbox "destination" of account "my-account"
    end repeat
end tell
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.