In the I scan for a date within the document and set a custom meta date field. (This still cannot be done, without using a script, correct?). Then I change a custom meta field to the value “ready to be renamed”:
In the following rule I check, if the custom meta field is set to “ready to be renamed” and change the file name using the date which is set in the the custom meta date field which was set in the rule before:
How do you determine the sequence in which the smart rules are executed? And how do you determine that the second rule is not executed? Do you see any messages in the protocol?
Perhaps it might be easier to use just one rule with one JavaScript script, thus avoiding the awkward fiddling with “Status”.
Aside: You might want to check the spelling you use in the “Titel” field in the first rule … (Just wondering why you replicate a tag in a custom metadata field).
How do you determine the sequence in which the smart rules are executed?
I assumed that the rules run in the same order as they are laid out in devonthink (from top to bottom).
And how do you determine that the second rule is not executed? Do you see any messages in the protocol?
The second rule is a least not executed after the first rule, because the “Status” field is still set to to “ready to be renamed” and not “renamed”.
Perhaps it might be easier to use just one rule with one JavaScript script, thus avoiding the awkward fiddling with “Status”.
This would work, but I the second rule is kind of generic and is run after several other rules and I would like to dermine the order of the rules within the UI of devonthink an not in the javascript.
Aside: You might want to check the spelling you use in the “Titel” field in the first rule … (Just wondering why you replicate a tag in a custom metadata field).
The second rule is set to On Import but there’s no import happening. There is no event trigger for when metadata changes on a document. You could use an intervallic trigger, e.g., Every Minute.
It’s possible you could use the Apply Rule action and run the second rule explicitly, but this would also depend on the specific rule. However, you did say it’s generic so maybe it would work here.
Both rules are triggered On Import. The first rule is executed on import and sets the metadata. Shouldn’t the second rule be then excuted on the imported document after the first rule is finished?
The sounds played depend on the order of the rule in the Smart Rules list. But the matching criteria are simple and satisfied by the imported document.
However, the Status of the document in your scenario is not set on import. It’s set by the previous smart rule.
If you had a smart rule that tagged a file on import, a subsequent smart rule would not execute with an On Tagging event trigger, even if the criteria matches the tagged file. A smart rule doesn’t initiate event triggers in other smart rules.
In this instance, you could use On Tagging to do some action when you manually tag an item but call it from another smart rule. This would correctly be called chaining smart rules.
function performsmartrule(records) {
const app = Application("DEVONthink 3");
app.includeStandardAdditions = true;
/* Loop over the records selected by the smart rule */
records.forEach(r => {
if (app.getCustomMetaData({ for: "status1", from: r }) == "ready to be renamed") {
app.logMessage("rename document");
renameDocument(r)
app.addCustomMetaData("renamed", { for: "status1", from: r })
}
})
}
If it were me, I’d try to figure out if the file needs to be renamed by looking at the name instead of fiddling around with a meaningless status. What’s the point of having a bunch of renamed files sitting around with a status saying “renamed”? Or perhaps set the status to “”?