10.5: A workaround for broken Mail rules

Mar 20, '08 07:30:04AM

Contributed by: MurphyM

Leopard has problems with rules in Mail.app that call AppleScripts that, in turn, generate a new Mail message. The scripts won't run from the rule, even though they work fine in Script Editor. Here's a workaround...

Have your rule in Mail run an AppleScript that calls a shell script, like this:

do shell script "/Users/murphymac/shell_script.sh"
Then have that shell script run the main AppleScript. Here's an example of what the shell script (shell_script.sh in this case) might look like:
osascript /Users/murphymac/MsgFetch.scpt
Design the main AppleScript so it targets certain messages, like a Mail rule would. Here's a simple example for selecting messages based on subject:
tell application "Mail"
  delay 1
  tell (first message of inbox whose subject is "macosxhints") 
    to if exists then
    -- insert actions to be taken here
  end if
end tell
Here's a working example of a script that checks the inbox and acts on certain messages.

As an alternative to scripts that are triggered by a Mail rule, you can run an AppleScript on a schedule. The script can check the inbox for messages with certain subjects, dates, flag status, etc. If they find a match, they can perform the required task. See the link above for examples. This approach essentially mimics the role of Mail rules.

Comments (1)

Mac OS X Hints