Shortcut for moving an email to another folder in Mail.app
Solution 1
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.
Solution 2
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
Solution 3
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
Related videos on Youtube
![Open the way](https://i.stack.imgur.com/0C7Na.jpg?s=256&g=1)
Open the way
Updated on September 18, 2022Comments
-
Open the way almost 2 years
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?
-
Open the way about 12 yearsthanks 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?
-
Open the way about 12 yearsok, 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!
-
slhck about 12 yearsBoth 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..
-
HikeMike about 12 years@flow What does AppleScript Editor show in the output pane when you run
tell application "Mail" to accounts
? -
Open the way about 12 yearsI get: syntax error: Mail got an error: Can’t get mailbox "Personal" of account "this_is_my_account".
-
Open the way about 12 yearsthe mailbox "Personal" is ON MY MAC
-
slhck about 12 yearsPinging @DanielBeck – any idea? flow, you sure you get that syntax error when running
tell application "Mail" to accounts
? There's no mailbox involved here. -
HikeMike about 12 yearsThat's what my command is supposed to tell us. Doesn't look like @flow is actually executing that line only.
-
Rogerio Silva about 10 yearsDude. I had created a similar AppleScript to ask for a destination mailbox and move the currently selected message(s) to it, but I was launching it with Alfred/Spotlight. It had never occurred to me to create it as a service. Life-changing answer. I'd upvote this 50 times if I could.