Apple Mail: Flag message from keyboard
Solution 1
The problem is that your flag's name was the same as a folder's name. For the shortcut to work, the flag must be unique in Mail.app's menu items. Since folder names are navigable to via the menu system, it is conflicting with your flag name.
I know you've accepted an answer, but another easier solution would have been to name your flag something like "@TODO", "TODO!", etc... I use "@Flag Name" for all my flags and it works like a charm.
See: Link to my Message->Flag menu with shortcuts
Article Describing Configuring short cuts: Making OS X Lion Mail.app Flags more useful
Solution 2
Mail.app flags are accessible via AppleScript in the flag index
property of the message
object. The index starts at 0 (-1 meaning “no flag”), counting up in the order in which flags are listed in the Mail menu. You can either create a pure AppleScript:
tell application "Mail"
set selectedMessages to (selected messages of front message viewer)
if (count of selectedMessages) is greater than 0 then
repeat with theMessage in selectedMessages
set flag index of theMessage to <index>
end repeat
end if
end tell
and assign it a hotkey through a launcher application like FastScripts, or embed it into a system service, by creating a Service Automator workflow set up to:
- take no input (!)
- in Mail.app
with the first item a “Get Selected Messages” action, followed by a “Run AppleScript” action with the following code:
on run {input, parameters}
set selectedMessages to input
tell application "Mail"
if (count of selectedMessages) is greater than 0 then
repeat with theMessage in selectedMessages
set flag index of theMessage to <index>
end repeat
end if
end tell
return input
end run
You can then assign a hotkey to your newly created service in the System Preferences, Keyboard settings:
ADDENDUM: if you prefer a pure GUI solution, you can also use MailActOn by Indev Software. Using MAO, you can setup a MailActOn rule (in Mail’s Rules setting panel, which MAO extends) to assign the flag. If you give that rule a unique MAO trigger letter and make sure the “Control+ActOn key applies rule” setting int the MAO preferences is checked, you can assign the flag to any selected mail with Ctrl+<trigger letter>
:
Solution 3
Here's a method that is much easier in that it uses only the System Preferences (no scripting or third party software needed):
- Open System Preferences > Keyboard > Keyboard Shortcuts
- Click "+" to add a new shortcut
- For Application, choose Mail from the drop down (to avoid conflicts in other applications)
- Enter the Menu Title as it appears in Mail (Red, Orange, Clear Flag, etc.)
- Enter the desired keyboard shortcut for that menu option (I use option+R, option+O, etc.)
- Click Add
- Repeat for as many color flags as you like
No muss, no fuss! Since flag color menu choices are unique and by assigning the shortcuts only to the Mail app, hard to see how it could cause any unwanted side effects. Works like a charm in Mail 5.3 and OS X 10.7.5, can't vouch for older versions.
hibbelig
Updated on September 18, 2022Comments
-
hibbelig almost 2 years
One of the flags in Apple Mail can be applied to a message using Command-Shift-L. Is there a way to apply any other flag?
I renamed one of the colors to TODO, and I set up a keyboard shortcut for the TODO menu item in Apple Mail, using System Preferences. When I used this keyboard shortcut, Mail switched to the TODO folder...
-
hibbelig over 12 yearsI never thought of using AppleScript. I kind of assumed there must be a "native" solution. Your suggestion works perfectly. I used the FastScripts approach, since I already have FastScripts. I would never have figured out how to do it in AppleScript!
-
Chad Daniels over 12 yearsActually, there is a way to do it without AppleScript I missed when answering at first, but it involves using commercial software – see my addendum to the answer.
-
hibbelig over 11 yearsAs mentioned in the original question, I had tried that, but instead of applying the flag, it changed to the folder, when I pressed the key. Not sure why it is behaving differently for you than me.
-
Helio Junior over 11 yearsThis only works if you don't have the flagged folder in your favorites. The reason is that the first menu item "Orange" will match is Mailbox, Go to favorite, Orange.
-
Marián Černý over 4 yearsGreat. Works on Mojave. Now it is in System Preferences > Keyboard > Shortcuts > App Shortcuts.