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...

link|improve this question
feedback

2 Answers

up vote 4 down vote accepted

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:

screenshot

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>:

screenshot

link|improve this answer
I 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! – hibbelig Oct 19 '11 at 4:20
Actually, 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. – kopischke Oct 19 '11 at 13:10
feedback
try
    tell application "Mail"
        repeat with m in (get selected messages of message viewer 1)
            set flag index of m to 4
        end repeat
    end tell
end try

-- 0: none, 1: red, 2: orange, 3: yellow, 4: green, 5: purple, 6: gray

And Assign a shortcut to running a script in OS X - Super User (I.e. use FastScripts, as the OP already seems to do.)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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