With the trend toward email bills, it is easy for them to get lost in the shuffle of email. It is harder to just put them on the counter and easily go through that pile looking for anything that might be a bill. I want a reminder. The problem is, Apple Mail doesn't have a clean way to create reminders based on an automated rule or keyboard action. I could drag and drop the mail message to Reminders or to Calendar to create events, manually tweaking the calendar it goes to (or the Reminder list) and any due dates, but I want to be Lazy. So I wrote a little code.
Apple Mail supports AppleScript, so that's the language I used. AppleScript has the advantage of supporting a kind of object reference model to query the Mail message and extract elements from it, as well as create Reminders. There is no clean library documentation for the Reminders that I could find, so this was pieced from lots of Googling…
— Create reminders for the selected email
— BEGIN EDIT SECTION
set myList to "Bills"
set leadtime to 7
— END EDIT SECTION
— the newline char
set newline to ASCII character 10
— First, grab the email we want, setting a few variables based on the message.
tell application "Mail"
set theSelectedMessages to selection
set the selected_message to item 1 of theSelectedMessages
set message_id to the message id of the selected_message
set msg_subj to the subject of the selected_message
set msg_body to content of the selected_message
set msg_from to (sender of the selected_message as string)
end tell
— Create a formatted link to point to the email
set msgLink to "message:%3c" & message_id & "%3e"
— Now create the reminder. One line didn't seem to do what I wanted cleanly
— Reminders are made by creating the object then setting the properties of the object
tell application "Reminders"
set newremind to make new reminder in list myList
set name of newremind to msg_subj
set remind me date of newremind to (current date) + leadtime * days
set body of newremind to msgLink
end tell
At least on manual runs, it works. Time will tell if it truly does what I want.