Finding All Groups in a Database

Hi I am trying to use Applescript to pull all the groups in a database ( to populate a dropdown in an HTMLPrompt so I can assign a new record to one of the existing groups)

Referencing the Dictionary I have tried this…

tell application id "DNtp"
	set myDBGroups to (name of every parent of database "Test" whose (tag type is group tag))
end tell

But this only returns {} when there are existing groups. Do I have the syntax wrong (or something else). Any help gratefully received

I don’t have access to DT right now but I guess that I’d look for type is group.

1 Like

Great thanks @chrillek. Actually just made an amend it is…

tell application id "DNtp"
	set myDBGroups to (name of every parent of database "Test" whose (type is group and tag type is not ordinary tag))
end tell

Just a remark: getting the name of a group might be less useful than getting the group itself or its UUIDs. Identical names can occur several times in a database, UUIDs are unique as are the group records themselves.

Thanks @chrillek a good point. In my use case I have a pre-set bunch of 5 different groups in each of my databases so I don’t think I will run into this issue.

The KM macro asks the user to select one of 4 databases and then (dependent on the result) the user can selects which group the record is to go into (populated from the above). Another macro can then be run and allow the use to select from a database specific bunch of tags to allocate to the record

This one function alone has enabled me to drop Drafts never mind all teh other cool stuff I can do

I wonder whether you could add a suggested location (so the top suggestion from the AI) to the initial dialog…? That might well save you time.

I’ve actually just played with classify and it seems it only works within a database rather than across databases; so

tell application id "DNtp"
	set theRecords to the selection
	set theRecord to first item in theRecords
	set theList to classify record theRecord
	return theList
end tell

will only propose locations within the database the selected record is currently residing in. As a result, I get no results at all for records within the global inbox. @BLUEFROG is that behaviour intentional? The results are also not the same as the suggestions offered by the *See Also & Classify" inspector. Is there any way to get those same suggestions in AS?

It would be great to have access to those, but unfortunately in other threads it has been said that the classify command has not changed since DT 1.0

1 Like

Criss would have to respond on this but no it’s currently not possible to classify across databases via AppleScript.

  • Classification used to only work in a database.
  • With DEVONthink 3, classification works across databases.
  • With a later point release, we added the option to again only classify in the current database via the checkbox in the See Also & Classify inspector.

It may be just a leftover legacy behavior or it may be intentional for performance reasons. Ye wizard of olde, Criss know. :slight_smile:

1 Like

Just wanted to bump this towards @cgrunenberg to respond at his leisure; I’ve just stumbled across this weakness in DTs AS capabilities again when trying to script world domination. DT has such powerful AS support, that the inability to get the list of classification suggestions (as displayed in the inspector) via script is almost an anomaly.

The next release will support this and revise the commands compare and classify to easily use all databases.


That is great news, thanks Criss!

And this will make (slow) workarounds used in scripts like the following ones obsolete:

E.g. a test revision of Markdown See Also (see support assistant) is much faster and the results are identical to the inspector.