1

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?

4 Answers 4

2

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.

9
  • 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? Apr 25, 2012 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! Apr 25, 2012 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, 2012 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, 2012 at 5:14
  • I get: syntax error: Mail got an error: Can’t get mailbox "Personal" of account "this_is_my_account". Apr 27, 2012 at 8:49
1

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
1

I was looking for the same solution, to move messages to a folder and using the dictionary I found this to work in Yosemite.

tell application "Mail"

  set the_messages to selection
  repeat with this_message in the_messages
 set theSender to sender of this_message  
move this_message to mailbox "BILL PAY/Mortgage & HOA" of account "iCloud" -- a folder        contained by another folder

 end repeat
end tell 
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .