Running up against another AppleScript issue in DT4 that I can’t figure out… works previously in DT3.
tell application id "DNtp"
set theGroup to get record with uuid "866C1DBF-055E-49CF-BC03-087C64350DD8" -- Bible Study
tell (current date) to set startOfToday to it - (its time)
set theRecords to (children of theGroup whose tags contains "Bible Study" and modification date > startOfToday and record type is not group and record type is not feed)
end tell
The error I am receiving is DEVONthink got an error: Can’t make “Bible Study” into type array or missing value.
Applescript is supposed to be able to find a string within an array… if I change the string to an array (ie, whose tags contains {“Bible Study”}), the script passes without an error but also doesn’t find the string within the tags array…
if I remove the ‘tags contains “Bible Study” and’ portion of the script it works and I can look at the records I want that DO contain a tags array containing “Bible Study”, but the result also finds records I don’t want to include that don’t contain that tag.
Thanks as always for scripting assist!
Rick
Development would have to assess this, but I can confirm the behavior has changed.
Here is DEVONthink 3.x…
And version 4.x…
As always, would like to see if there’s a “bug” there… but also get a working answer. With the second part in mind, I’ve gotten a search function to work:
set matches to search "tags:{\"Bible Study\"} scope:" & theGroupID & " mod date:>=Today" in root of db
but also want to report that a different order of search terms
set matches to search "tags:{\"Bible Study\"} mod date:>=Today scope:" & theGroupID in root of db
does not work in a script NOR does it work in the search bar of DT4
Rick
mod date:
is not a valid prefix and {…}
is reserved for subpredicates but not supported in a tags condition.
intriguingly, the search term does not work using tags without the brackets but does (or at least finds the records I’m attempting to find) when the brackets are included…
and mod date: gives me the same results as using modification date:

also intriguingly, if I put a comma after the closing bracket, the search term finds the tags, but if I don’t include the comma, it just finds the string within any part of the record, contents, tags, etc. I’m confusing myself playing with these search terms!
As noted, mod date:
is not a valid search prefix.
modificationDate:
or the abbreviated modified:
are the correct prefixes.
PS: Using the Advanced search editor is a good way to learn or double-check the raw search syntax.
Version 4‘s script suite has been completely rewritten and is now based on the modern .sdef
format. And although it‘s as compatible as possible, some scripts have to be updated. Especially whose
statements are subject to the whims of AppleScript.
1 Like
Good to know. I figured that may be the cause but didn’t know for certain.
Still not sure how to use the “tags” prefix properly, but the following finds what I want:
set theRecords to search "\"Bible Study\", scope:" & theGroupID & ", modification:>=Today"
not including the “tags:” search prefix, yet including a comma after the string appears to find the tags Bible Study and does NOT include the string “Bible Study” within the content.
OR
set theRecords to search "tags:Bible Study scope:" & theGroupID & " modification:>=Today"
as it appears the tags search prefix doesn’t want any quotations despite the tag containing a space, and therefore can’t contain multiple tags as a search criteria(?)
Again, use the Advanced search criteria editor to see what’s going on.
Adding quotes considers that part of the tag so unless your tag actually contains quotes, you won’t get matches.
Applied tags are not space delimited; they’re semi-colon delimited. This is proper syntax…
And in a script…
tell application id "DNtp" to search "tags:devonthink support;testing" in current group
Also, as AppleScript’s list processing has always been a weak point, it’s quite possible the issue stems from the fact that tags are a list
and handled differently with the .sdef
format. Filtering with whose
clauses produces a trimmed down set of children. You can then walk that list in a repeat
loop to query the tags, e.g.,…
Given the list is usually going to be small, this should be very performant.
ah. semicolon. got it. I tried but couldn’t get the advanced search to show me how it formatted multiple tags. Not sure what went wrong on my end to cause that.
Appreciate you all walking through this with me as usual.
This works – or rather it doesn’t throw an error
tell application id "DNtp"
set l to contents of database "Test" whose tags contains {"tag"}
end tell
Interesting and definitely an option if not directly dealing with a specific group!
The next release will accept both strings and arrays and therefore support queries like whose tags contains "tag"
or where its tags contains {"tag1","tag2"}
.
3 Likes