Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use some Mail rules on an as-needed basis via the keyboard Apps
If you've ever explored the possible actions offered by Mail's rules, you've probably wished that you could apply some of them to any message on command. For example, you might want to move the selected messages to one mailbox or another at the press of a hotkey, or to replicate Eudora's labels by changing the text color of messages in their mailboxes (Mail's GUI only allows changing their background color, which I dislike as much as OS X's Finder labels).

The problem is that Mail's rules are intended to run automatically on incoming or outgoing emails, so such "manual" rules cannot easily coexist with automatic rules. The good news is that it's very easy to work around that conflict using AppleScript and Keyboard Maestro.

The trick is to group the "manual" rules at the top of the list, end each of them with with 'Stop evaluating rules,' and to keep them disabled so they won't interfere with automatic rules. To run one of these rules manually, you need a Keyboard Maestro macro that will enable that particular rule via AppleScript, tell Mail to 'Apply Rules' (which will run it on the selected messages), and then to disable the rule.

For example, let's make a rule that will move the selected messages to the mailbox named Important. From Mail's preferences, create a new rule named 'Move To Important' and set it like this:
If [any] of the following conditions are met:
  [every message]

Perform the following actions:
  [Move Message] to mailbox [Important]
  [Stop evaluating rules] (don't forget that one!)
Click OK to save and close the rule. Then make sure to uncheck its "Active" checkbox and move it above any rule intended to run automatically. Don't skip this step!!

Then create a new macro in Keyboard Maestro, in a group that makes it active when Mail is frontmost, and set its actions to:
Execute AppleScript:
  tell application "Mail" to set enabled of rule "Move To Important" to true
Type the keystroke:
  ⌥⌘L (the shortcut for Mail's Message » Apply Rules menu item)
Execute AppleScript:
  tell application "Mail" to set enabled of rule "Move To Important" to false
Give this macro a hotkey, and you're done!

Alternatively, if you prefer to run those rules by clicking on buttons instead, you could use Keyboard Maestro's palette, or you could could save an AppleScript script that triggers this macro (Keyboard Maestro will give you the contents of that script) and drop it into a DragThing dock. The possibilities are almost infinite.

When I first got the idea to do this, I was afraid it could interfere with automatic rules if Mail happened to download mail at the same time I ran a manual rule, but I've used lots of such rules for more than a year, now, without any problem. Just don't trigger a manual rule while Mail is already downloading mail, and you shouldn't run into any problem either. Enjoy!
    •    
  • Currently 2.53 / 5
  You rated: 5 / 5 (15 votes cast)
 
[8,381 views]  

Use some Mail rules on an as-needed basis via the keyboard | 4 comments | Create New Account
Click here to return to the 'Use some Mail rules on an as-needed basis via the keyboard' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use some Mail rules on an as-needed basis via the keyboard
Authored by: V.K. on Feb 08, '10 09:12:06AM

A nice hint. One correction. Automatic mail rules don't apply to sent messages, only to incoming ones.



[ Reply to This | # ]
Use some Mail rules on an as-needed basis via the keyboard
Authored by: Anonymous on Feb 08, '10 09:18:54AM

Interesting hint, and made me discover quite a remarkable program in Keyboard Maestro...

However, if this is your main use for the utility, you might as well check out Mail Act-On... it makes developing keystroke rules (as well as outbox rules) very simple for Mail.app!



[ Reply to This | # ]
Or try MsgFiler
Authored by: FlaSheridn on Feb 08, '10 09:29:29AM

Or for the original purpose, “to move the selected messages to one mailbox or another at the press of a hotkey,” you might check out http://www.tow.com/msgfiler, designed to do exactly that. (Disclaimer: Adam Tow is a friend and fellow Newton User Group officer, and I actually use KeyboardMaestro instead.)



[ Reply to This | # ]
Or try MsgFiler
Authored by: flip on Feb 09, '10 10:04:52AM

I use Keyboard Maestro for tons of other stuff. I prefer to use one application that allows me to do pretty much anything rather than a different application for everything I want to do. :)



[ Reply to This | # ]