Run externally from Script Editor, this script will trigger smart rules whose conditions are fulfilled by the selected records:
tell application id "DNtp"
set theRecords to the selection
repeat with theRecord in theRecords
perform smart rule trigger import event record theRecord
end repeat
end tell
Running the same script from within a smart rule, however, does nothing:
on performSmartRule(theRecords)
tell application id "DNtp"
set theRecords to the selection
repeat with theRecord in theRecords
perform smart rule trigger import event record theRecord
end repeat
end tell
end performSmartRule
Select a record for which a smart rule would trigger on import (the same record as used previously), select Apply Rules from the context menu, select above rule, and nothing happens. This used to work, and is essential to be able to trigger additional rules on records which are OCR’d by a rule. I have spent some time experimenting with this; rules which previously worked do not work any more. I’m not sure when this behaviour changed, but could it pls be changed back?
Yeah, I knew you would say that, but unfortunately that is only helpful if you know which rule needs to be triggered. I have a smart rule which performs OCR on any PDF with 0 words; those PDFs can come from multiple sources and previously were then dealt with by one of approx. 50 rules. I can’t even automatically determine which rule the PDF should be sent to before it has been OCR’d, as the rule conditions are routinely based on the contents of a record.
I’m guessing the functionality has been intentionally crippled to avoid trigger loops; but, to be quite honest, those who are writing scripts need to know what they are doing and be aware that they can cause damage; the delete command, for example, hasn’t been removed
Thanks I wonder whether a loop could be recognised (e.g. if a rule runs for the 10th time in x seconds, or if DT never returns to settled state or …), and the progress indicator opened (with the termination option) in such a case.
(I admit to having used slightly uncharitable words; I’ve just spent hours trying to figure out what I was doing wrong only to find that I’m just trying to use something no longer available )
That’s ideal. But currently no rule is being triggered; so if perform smart rule trigger import event record theRecord could be made to work again from inside a rule, all would be great.
@cgrunenberg just checking, should this work right now (3.8.3)? I can’t get it to work in my test.
on performSmartRule(theRecords)
tell application id "DNtp"
repeat with theRecord in theRecords
perform smart rule name "Resources: save content" record theRecord
end repeat
end tell
end performSmartRule
It’s a pretty complex rule that might be irrelevant to this question so I’ve craeted a small test setup with two rules “Test 1” and “Test 2”:
When running Test 1 as a Smart Rule (Apply Rule - it currently matches 2 documents starting with “1984”) it does nothing. Running the same code (using selection as list) for theRecords) from Script Debugger / Editor it works as expected and shows the alert.