Mac Mail Macro

Hi All,

for whatever reason, the rules I've setup in Mac Mail only run when I manually run them. Maybe I'm missing something, but very frustrating.

I'm hoping to solve this issue by setting up a timed macro to run once a day that will run the rules for me. I've tried to figure this out but running into some issues. I need to select all the messages from 2018 (I've setup a smart folder for this) and then apply rules. Any help would be greatly appreciated! Thanks. Marc

I would recommend diagnosing why your mail rules only run manually. It may be symptomatic of a deeper problem that you'll be happy you fixed rather than ignored.

But here's a quick, rough outline to what steps I would implement to build such a macro:

Every day ? Do the messages from 2018 that had the rules applied to them yesterday need to have those same rules applied to them again today ?

My solution would be to reach for AppleScript and see how viable that is at achieving the desired result. You would need to write some code that performs the actions that would have been performed by the rules.

Then, in the initial instance, you can get the code to act upon all messages from 2018:

use application "Mail"

set _M to a reference to (every message of the inbox ¬
	where date received ≥ date "Monday, 1 January 2018 at 0:00:00")

tell _M
	
	(* code that performs what the rules would have done *)
	
end tell

Subsequent to this, you could (if more appropriate than running the rules on messages who have had them run already), get the code to act only on messages from yesterday and today (assuming the macro is set to run once a day):

use application "Mail"
use scripting additions

set yesterday to (current date) - 24 * hours

set _M to a reference to (every message ¬
	of the inbox ¬
	where its date received ≥ yesterday)

tell _M
	
	(* code that performs what the rules would have done *)
	
end tell

Of course, this will apply the rules to some messages twice, but this is a simple way to make sure the time of day that the script is run doesn't lead to any omissions.

Macro-wise, there's a cron trigger that'll let you dictate a schedule for the macro to run:

The number 13 can be any value from 00 to 23 to specify what hour in the day to execute the macro.

1 Like