Back on the Mac…
Before attempting to put some unknown and untested code into a smart rule to possibly mangle your databases, you should put the script (copy/paste) into Script Editor, set this app’s language selector (upper left) to JavaScript, select a record in DT and then run the script in Script Editor. Use a copy of a record, not the original, to prevent damage.
As you’ll then see, it doesn’t do anything to your record(s), but simply retrieves the 2nd and 3rd line from the selected PDF document, storing them in appropriately named constants. If, for example, you’d want to change the name of your record to the text found in the third line, you’d use
record.name = thirdLine;
DO NOT DO THAT without adding some safeguards, checking that thirdLine
(or whatever else you come up with) is really what you want the name for your record to be. It could, for example, be a whole paragraph of text, which would make for quite an awkward name.
Now, if you have tested the code, and it does what you want, you can add it to a smart rule. For that to work, you have to set up a scaffolding like this
function onperformsmartrule(records) {
records.forEach(r => {
const paragraphs = r.plainText().split('\n');
…
})
}
and add this as internal JavaScript (!) to your smart rule. The name of the function must be onperformsmartrule
, everything else is up to you.
You’re not forced to use JavaScript, AppleScript is preferred by many people here (not me, though). You can’t, however, mix the two. tell Application
and repeat with
etc are all AppleScript constructs that will cause the script compiler to fail and prevent your script from running.
There are a lot of AppleScript and some JavaScript examples floating around in this forum. There’s also my Website on JavaScript for Automation with general information on JavaScript in the AppleVerse and some examples for DT as well as for other apps.