Mail message to Reminders Item and Trello Card

 Wanting to keep track of work tasks and not wanting to use the employer supplied task manager (Outlook) I created the following workflow to create a Reminders item and Trello Card from an email I send to my personal email account. 

Here are the steps that you need to follow to replicate this workflow.

1. Modify the Applescript Configuration to suit your needs, eg Trello email etc

The Applescript needs to be saved in the following location

/Users/(User Name)/Library/Application Scripts/com.apple.mail 

I use the method of using a standard Applescript rather than one designed specifically for Mail Rules as I find the Mail Rules version does not run reliably. 

2. If you want to use Reminders Tags, create a Shortcut as follows

Shortcut to set Reminders Tag

3.  Create a Rule to trigger the Applescript if a Mail message is received using your nominated Task Tag, *** in my case. 

4. Create an email and prepend *** to the Subject. If you want to set a due date beyond today, just add a number in the Subject line. Send the email to an email account set up in Apple Mail, 

The Applescript will extract the Subject of the Mail message, stripping out unwanted characters and text to create a task in Reminders. If you set a numeric value in the subject, the script will use the first number found and add it to the current date to select the due date. 

The script will then trigger the Shortcut to add a Tag to the Reminders item.

 A new email will be generated using the refined Task name as the subject, and the due date added to the original email's contents. The message will be automatically sent to the email address associated with the Trello Board. This results in a new Card being created. 

This video demonstrates the workflow.

Hope you find this example of value; get in touch if you have any questions.

##############################################
# Title: Email Task to Reminders
############################################
# Iain Dunn
# Logic2Design
# www.logic2design.com
# logic2design@icloud.com
# Last update: 6 February 2022
# Version: 1
# Contributors and sources
#
##############################################
# Configuration
##############################################
set theFrom to "" -- From email address
set theTo to "@boards.trello.com" --Trello Board email address
set theList to "Do" -- Reminders List
set theTime to 9 -- what time of day to set the Reminder for
set taskTag to "***" -- prepend this to your email Subject follow with a number (days) to set the due date
--Optional
set MailTags to 1 -- set to 1 to use MailTags
property assignedKeywords : {"Work"} -- MailTag that you would like to allocate
##############################################
# Code
##############################################
tell application "Mail"
--Get the messages in the Inbox
set messageList to every message in inbox whose subject contains (taskTag as list)
repeat with theMessage in messageList
# Get theTask name
set the theTask to (theMessage's subject as string)
# Get theContent
set the theContent to (theMessage's content)
# Get the message URL
set theOrigMessageId to theMessage's message id
set theUrl to {"message://%3C" & my replaceText("%", "%25", theOrigMessageId) & "%3E"}
# Get days to add to Current Date for remDate - number specifed in Subject, ***1 naming convention
set s to quoted form of the theTask
do shell script "sed s/[a-zA-Z\\']//g <<< " & s
set dx to the result
set numlist to {}
repeat with i from 1 to count of words in dx
set this_item to word i of dx
try
set this_item to this_item as number
set the end of numlist to this_item
end try
end repeat
set dueDate to 0
try
set dueDate to item 1 of numlist
end try
# set Reminder Date
set remDate to ((current date) + dueDate * days)
set hours of remDate to theTime
set minutes of remDate to 0
set seconds of remDate to 0
# replace text in theTask name
set theTask to my replaceText(taskTag, "Task -", theTask) -- remove task indicator
set theTask to my replaceText(" [SEC=UNOFFICIAL]", "", theTask) -- remove work security setting
set theTask to my replaceText(dueDate, "", theTask) -- remove days to use to set due date
# make Reminder
my makeReminder(theTask, theUrl, remDate, theList)
-- MailTags
if MailTags = 1 then
#Tag the Message - optional for Mailtag users
using terms from application "SmallCubed MailSuite"
set keywords of theMessage to assignedKeywords
end using terms from
end if
--Send task to Trello
tell application "Mail"
set theNewMessage to make new outgoing message with properties {sender:theFrom, subject:theTask, content:"Due Date - " & remDate & return & return & theContent, visible:false}
tell theNewMessage
make new recipient at end of to recipients with properties {address:theTo}
end tell
send theNewMessage
end tell
# Archive the Message
tell application "Mail"
--set flagged status of theMessage to false
set mailbox of theMessage to mailbox "Archive" of account "iCloud"
end tell
# Set Reminders Tag
tell application "Shortcuts Events"
run the shortcut named "Reminders set Work Tag"
end tell
end repeat
end tell
##############################################
# Functions
##############################################
on makeReminder(reminderName, reminderBody, reminderDueDate, reminderListName)
tell application "Reminders"
if not (exists list reminderListName) then
make new list with properties {name:reminderListName}
end if
set existingReminder to reminders where due date = reminderDueDate and name = reminderName
if existingReminder is {} then
return make new reminder ¬
with properties {name:reminderName, body:reminderBody, due date:reminderDueDate} ¬
at list reminderListName
end if
return missing value
end tell
end makeReminder
on replaceText(find, replace, textString)
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to find
set textString to text items of textString
set AppleScript's text item delimiters to replace
set textString to "" & textString
set AppleScript's text item delimiters to prevTIDs
return textString
end replaceText




Comments

Popular posts from this blog

Obsidian Daily Digest Shortcut

Time Block Reminders tasks in Calendar

No Cost Web Hosting