Two important pieces of info missing. First is your email client! I'm really hoping that's Mail, else this could be difficult... Second is whether you want any info from the email to be included in the created task.
Have you got a Shortcut that works for creating your new Things task? (They're recommending Shortcuts over AS now, though it would also be doable with AS.)
Then you write an AppleScript that executes your Shortcut. That could be as easy as
tell app "Shortcuts" to run "My Shortcut"
...but will be more involved if you want to make use of data in the email.
Then all you need is a Mail rule triggered on incoming emails "To" example@me.com that:
Executes the saved AppleScript
Marks the email as read
Moves the email to mail folder "Example"
But I suspect you want to include details from the email -- maybe using the subject as the task title and the body as task text. An example email along with the required resulting task would be a big help here.
Edit to add:
Don't forget that there's also a "Mail to Things" facility. You could use that in conjunction with their "Run Inbox Rule" Shortcut (suitably edited and run periodically) to do what you want without cluttering your own email account. Especially useful if you aren't using an email client that can run scripts from rules.
I think everything you need to do you can do via a shortcut, no need to involve KM using that simple snippet from @Nige_S below, just shoot it to a shortcut and you're off.
Unfortunately "Mail to Things" does not allow you to do anything but dump the email in Things inbox. OP wants to add it to a date and assign it to a project.
Can Mail run Shortcuts from Rules now? AFAIK it's still only AppleScripts, which is why you need to go the round-about way and use AS to run the Shortcut.
Which is why you then periodically run the "Run Inbox Rule" Shortcut, to process the Things3 Inbox.
Ooooh.. You've given me an idea! Are you saying (and if you're not.. I am now) that the best way forward is to "skip" the apple mail piece altogether, mail to your 'things' inbox, then use a periodic applescript to process the inbox item?
For example, let's say I email to things:
Subject: Take the dog for a walk
Body:
I need to take the dog for a walk
tag: outside, exercise
project: Keep Rover Happy
date: today
Then the applescript can 'parse' that todo and add it to the correct project, tag it, date it, etc..?
But Cultured Code have kindly provided us with a "Run Inbox Rule" Shortcut that already does all the hard work. Tweak that to suit, make multiple different copies if you don't want to deal with too much logic in a single Shortcut, run the Shortcut(s) every hour to process your Inbox.
Not much of a Shortcuts user so I don't know if you can do a "periodic trigger" in macOS Shortcuts. But you can do one in KM -- and KM has an "Execute Shortcut" action
Thanks for the thoughts, got a bit further in the meantime:
-> Mail rules (forwarding, mark as read, move to folder)
-> Things3 Link Builder through a simple python script running with a periodic trigger in KM
The latter was easy to setup, works meticulous and easy expandable
""" organise things """
import webbrowser
import things
import pandas as pd
inbox = pd.DataFrame(things.inbox())
if len(inbox) > 0:
UPDATE = 'update?auth-token=xxx'
for _i, row in inbox.iterrows():
title = row['title'].lstrip().replace('Fwd: ', '').replace('Re: ', '')
param = f"when=tomorrow&title={title}"
if 'a@email.com' in row['notes']:
param = f"{param}&list=projectname"
things = f"things:///{UPDATE}&id={row['uuid']}&{param}"
webbrowser.open(things)
The Apple built-in email rules is not as easy to handle, nor does it feel reliable. How would you approach that part?
I'd do the whole thing with an AppleScript then rules.
Given an email with the subject New Things To-Do and the body containing:
Title: The Test Title
Note: This is the note in the to-do, keep it to one paragraph
Project: Project Name
...this AppleScript
set {theTitle, theNote, theProject} to {"", "", ""}
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
repeat with eachMessage in theMessages
set theContent to (content of eachMessage)
set AppleScript's text item delimiters to {": ", linefeed}
repeat with eachPara in (get every paragraph of theContent)
set eachPara to (get contents of eachPara)
if eachPara is not "" then
if text item 1 of eachPara is "Title" then
set theTitle to text item 2 of eachPara
else if text item 1 of eachPara is "Note" then
set theNote to text item 2 of eachPara
else if text item 1 of eachPara is "Project" then
set theProject to text item 2 of eachPara
end if
end if
end repeat
tell application "Things3" to make new to do with properties {name:theTitle, notes:theNote} at beginning of project theProject
end repeat
end perform mail action with messages
end using terms from
...will make a new to-do in the Project "Project Name", titled "The Test Title" and with the note "This is the note etc...".
Save the script as Things.scpt in ~/Library/Application Scripts/com.apple.mail and then your Mail rule to something like:
...and when an email with the matching subject arrives in Mail's Inbox you'll get a new to-do created in Things, the mail will be marked as read, then the mail will be moved to the "Done" mail folder.
You can tweak this to suit or make it do much more, following the Things3 AppleScript Guide. It can certainly be improved -- this was quickly thrown together yet is still 100% in testing (providing the named Project already exists! There's already a thing you can improve on...).