10.6: Move messages to a target folder via keyboard shortcut
Nov 30, '09 07:30:00AM
Contributed by: algal
This is how to assign a single keyboard shortcut to move a selected message in Mail.app into a designated folder -- e.g., a Gmail-style archive folder.
You can do this with Mail Act-On, but that costs money. You should be able to do this simply with OS X's assignable keyboard shortcuts, but that fails: OS X doesn't let you describe a command in a way that distinguishes between moving and copying a message. This method uses a keyboard shortcut plus a Service plus AppleScript. Ugly but it works.
There are two steps, creating a Service that will move the selected message(s) to a folder, and assigning a shortcut key to that service. First create a Service in Automator for moving the selected messages to a specific folder.
- Open Automator
- Choose Service as your template.
- Set the top drop-downs (for Service receives...) to 'no input' in 'Mail'
- Drag the Run AppleScript action into the construction area.
- Insert the following AppleScript, changing fastmail to the name of your account, and ---Archive to the name of your target folder.
on run {input, parameters}
set target_account to "fastmail"
set target_mailbox to "---Archive"
tell application "Mail"
set theSelectedMessages to selection
repeat with theMessage in theSelectedMessages
tell application "Mail"
move the theMessage to mailbox target_mailbox of account target_account
end tell
end repeat
end tell
return input
end run
- Save the Service as Archive message
Next, assign a keyboard shortcut to the Service:
- Go to the Keyboard Shortcuts tab of the Keyboard pane in System Preferences.
- Select Application Shortcuts in the left-hand column.
- In the right-hand column, hit the plus sign and add a shortcut with Application set to Mail, and the Menu Title set to Archive message, then set the Keyboard Shortcut to whatever you like.
It's an ugly, awkward, roundabout solution, but it seems to work.
[robg adds: As written, this script will move messages into folders that are associated with the specified Mail account -- that is, you've created a folder named Archive within the account 'fastmail' in your Inbox. If you'd rather have it file messages locally, to a folder in the On My Mac section of Mail, just remove the of account target_account bit from the end of the move the theMessage... line. I tested both versions of the script, and they work as described.]
Comments (10)
Mac OS X Hints
http://hints.macworld.com/article.php?story=20091115042357395