Created
February 6, 2022 07:54
-
-
Save logic2design/fbe68fcb9103bae3b6760610a1bccc78 to your computer and use it in GitHub Desktop.
This will convert an email to a Reminders task and new Trello Card
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ############################################## | |
| # 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment