Script to import flagged email to devonthink

I am looking for a way to automatically add flagged email to Devonthink. I would like to process email on iOS and if it’s something i want to save in Devonthink, flag it and have it get imported into Devonthink on my Mac.

There is no Mail Rule criterion for a Flagged state, so this would not be something easily done.

Also, flagging an email on iOS would not magically make it import to DEVONthink on your Mac. Mac Mail would have to be open and evaluating rules. And, it’s possible Mail on the Mac would evaluate the email before you flagged it on iOS and not trigger after you flagged it.

You could create a Smart Mailbox like this and process the results via the AppleScripts we provide in Mail…

Hi – I created a Smart Mailbox in Apple Mail, as illustrated above. Can you pls remind me how to “…process the results via the AppleScripts we provide in Mail…”

I assumed the next step is to create an Apple Mail Rule that watches for mail to appear in the Smart Mailbox and then perform the AppleScript action.

But I don’t see Smart Mailboxes as a condition to meet in Rules.

Thanks.

Mail rules are applied to all incoming & matching messages, therefore you probably have to use the conditions of the smart mailbox in the rule again.

Not sure if what you’re looking for is possible with Apple Mail, as “Flagged” doesn’t seem to be a condition for rules (probably because it’s a dynamic condition of mail, rather than a fixed one, like From).

This might not be what you’re looking for, but it is possible to automatically import e-mail to DT with more complex solutions like using Python to access the IMAP account directly. If you know your way around some (advanced) scripting you can take a look at: Auto-import new mail to DEVONthink. That script could be adapted to only process flagged e-mails. Bear in mind that this requires (quite) some effort from your side to keep the script running. But alas it is possible.

The dynamic part indeed can be the challenge

This might be easier to do through Zapier or Make.com or Microsoft Flow depending on your email provider. You could set a Rule or Trigger when you flag an email and then export the email to a Dropbox folder. Then index the Dropbox folder with a smart rule to import all new items in that folder.

Does it absolutely need to be items in the smart mailbox that get imported?
Otherwise, you could just duplicate messages to be imported into a specific Mail folder and use this script in combination with keyboard maestro to automate the importing. It’s pretty simple to set up and works great.