I’m playing with smart rules to automatically process scans that I import to DT. One thing I’d like to be able to do boils down to being able to process a file in different ways depending on whether the document’s “Sortable Document Date” is empty or not: if it’s not empty, I’d replace the date/time in the name of the item with that date, but I would want to leave the name as it was if there was no “Sortable Document Date” for the item.
Unfortunately, there doesn’t seem to be a way to condition the execution of a smart rule on whether the file has a non-empty “Sortable Document Date”. Also, unlike matches from scanning in the actions for the rule, the presence of “Sortable Document Date” in a rule doesn’t seem to cause the rule to be ignored. Instead, the rename takes place with an empty string interpolated.
Am I missing something obvious in the smart rules documentation that would help me do this?
I’m guessing that you can do pretty much anything if you put a script into the rule, but if that’s going to be the solution I might need some pointers to give me an idea of how to access things like the document date values for an item. AppleScript has never been something I’ve got heavily into.
The document date isn’t indexed and not searchable, currently it’s only retrieved on demand. A script is therefore probably the best solution. You can drag & drop DEVONthink 3 onto the Script Editor’s Dock/Finder icon to view the full AppleScript support including the
document date property.
I can work with that, thanks!
I had a bit of a poke around (as I said, I’m not an AppleScript expert) and managed to figure out how to get the document date out when it’s present, and how to rename the item. I did run into something I’d like confirmation of, though.
It looks like if the document does not have any parseable dates in it, that the “document date” property is not defined? Is that even the right terminology in AppleScript?
I think that means that if I want to base a conditional on whether there’s a parseable date in the document, I have two options:
- access the “document date of theRecord” in a “try” block and catch the error, or
- base my conditional on “count of all document dates of theRecord” being non-zero
Does that sound right?
If there is no detected
document date it will not return a
missing value, so using a
try… end try block would be the likely approach.
If it returned
missing value you could have used a standard
if… then loop.
An an example…
tell application id "DNtp"
repeat with thisRecord in theRecords -- or (selection as list) if working outside a smart rule
set docDate to document date of thisRecord
-- This will not error just because no date is detected.
-- It will rrror if you try to do something with it and there's none detected.
display alert "There is no document date detected in this document."