Can’t make new reminder in Mail Rule

I’m trying to create a Mail Rule that makes a new reminder whenever I get a payment notification from my internet provider. This AppleScript works when run directly or as a step in a Keyboard Maestro macro:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set remName to "Xfinity bill"
set remNotes to "https://customer.xfinity.com/#/billing"

tell application "Mail"
	set selectedMsgs to the selection
	repeat with theMsg in selectedMsgs
		set msgDate to date received of theMsg
		set remDate to msgDate + 5 * days
		set hours of remDate to 10
		set minutes of remDate to 0
		set seconds of remDate to 0
		tell application "Reminders"
			tell list "Expenses"
				make new reminder with properties {name:remName, remind me date:remDate, body:remNotes}
			end tell
		end tell
	end repeat
end tell

It creates a reminder in the Expenses list with the “remind me” date I want.

Of course, I don’t want to run this by hand; I want it run automatically through a Mail Rule. But setting a Mail Rule to run this nearly identical script fails.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set remName to "Xfinity bill"
set remNotes to "https://customer.xfinity.com/#/billing"

using terms from application "Mail"
	on perform mail action with messages theMessages
		repeat with msg in theMessages
			set msgDate to (get date received of msg)
			set remDate to msgDate + 5 * days
			set hours of remDate to 10
			set minutes of remDate to 0
			set seconds of remDate to 0
			tell application "Reminders"
				activate
				tell list "Expenses"
					make new reminder with properties {name:remName, remind me date:remDate, body:remNotes}
				end tell
			end tell
		end repeat
	end perform mail action with messages
end using terms from

Through some judiciously placed display dialog commands, I can tell that it fails when it tries to make a new reminder.

I suspect this has to do with privacy and permissions in Catalina. I opened the Privacy tab in the Security & Privacy preferences and tried to give Mail permission to access Reminders. But there’s no obvious way to add an app to the list.

As you can see, there’s no + button for adding an app. Dragging the Mail.app icon from Applications to the list doesn’t work, either.

Googling has led me nowhere. What am I missing?

Welp, I guess there’s no direct solution. My indirect solution is to move the emails to a special mailbox and set up an AppleScript to run periodically and create the reminders.

Sad to lose a simple and longstanding automation technique.

Hi,

Try this routine, it’s pretty much the same except I specify the rule that is being triggered and added a routine to create the Reminders list if it doesn’t exist.

use AppleScript version "2.4" 
use scripting additions

using terms from application "Mail"
	on perform mail action with messages theMessages for rule Test
		
		repeat with msg in theMessages
			set remName to "Xfinity bill"
			set remNotes to "https://customer.xfinity.com/#/billing"
			set remList to "Xfinity"
			set msgDate to (get date received of msg)
			set remDate to msgDate + 5 * days
			set hours of remDate to 10
			set minutes of remDate to 0
			set seconds of remDate to 0
			createReminder(remName, remNotes, remDate, remList)
		end repeat
	end perform mail action with messages
end using terms from

on createReminder(reminderName, reminderBody, reminderDueDate, reminderListName)
	tell application "Reminders"
		if not (exists list reminderListName) then
			make new list with properties {name:reminderListName}
		end if
		
		return make new reminder ¬
			with properties {name:reminderName, body:reminderBody, due date:reminderDueDate} ¬
			at list reminderListName
		
		return missing value
	end tell
end createReminder

Cheers

Iain

2 Likes

I tried your script (with a few minor changes), and when I applied the rule, I got the dialog box asking me to authorize Mail to control Reminders. That was the key; once Mail was authorized, the script ran perfectly. In fact, so did my original script without the “for rule” part.

Why was I suddenly asked to authorize Mail when I hadn’t been before? Beats me, but if “for rule” had anything to do with it, I’m grateful.