I would like to copy an email from Apple mail to the inbox of DEVONthink, and if it has a certain tag (from Mailtags) put it in a group and then see if the body contains ANY 8 digit number. If it has a number of this format, I want to add the number to an existing DEVONthink sheet contained in the same group. Can I do this with a smart rule?
Please understand I not looking for a single specific number. It has to find whatever 8 digit number might be in the message.
You might want to check out the Scan text action for smart rules. But
This requirement is not clear to me – what does the second “it” refer to: the document? the number? And what is this “list” – a Markdown document, a PDF, an Excel file? In any case, you’d probably have to script to add “it” to the “list”.
And if you’re scripting anyway, there’s no need for Scan text, I think. Just have the script search the text of the document for the 8-digit number and then add “it” to the “list” as well.
Thanks chenillek! I fixed the original description. A existing DEVONthink sheet containing 8 digit numbers would work! Can “Scan Text” be that specific about finding ANY 8 digit number (and not confuse it with say, a phone number?). Please understand I not looking for a single specific number. It has to find whatever 8 digit number might be in the message.
Well, if an 8-digit number happens to be also a phone number (like 03018990), how would you know that you do not need it? If there’s a simple rule to identify only those 8-digit numbers that do not happen to be phone numbers, you can write it down as a regular expression. Otherwise, all bets are off.
I already got that. The following scaffold script gets all 8-digit numbers in the records selected by the smart rule’s conditions. It doesn’t bother about phone numbers or zip codes on steroids – it simply gets all 8-digit numbers. Add it to the “Actions” part of the rule as internal script and modify so that it does what you want.
function performsmartrule(records) {
const app = Application("DEVONthink 3");
const table = app.getRecordWithUuid('UUID-OF-YOUR-TABLE');
records.forEach(r => {
const t = r.plainText();
const numbers = t.matchAll(/\d{8}/g);
/* Now "numbers" contains all 8-digit numbers in the current document */
if (numbers) {
/* Add it to the table using addRow or so */
}
})
}
Thanks! Phone numbers are usually provided to me with dashes because that is the convention where I live - so 212-484 etc. It looks like the script you provided won’t give me anything with a dash in it. But my scripting experience is limited. Am I right in saying that?