Programmatically create a smart group?

Is there a means of creating smart groups or saved searches from within Applescript? I wish to automate the creation of some smart group hierarchies.

Searches can be scripted; though I’ve not seen a script that creates Smart Groups. See the DEVONthink AppleScript dictionary for details.

Edit: but there is this example which might not work in DEVONthink v2.x

Unless I missed something , only the most primitive searches i.e. those made with:

search (verb)Search records by string, label, state/flag, locking and/or age

… can be scripted. Otherwise, it looks like you have to use:

lookup records with comment | file | path | tags

… and then do a tedious manual union of list.

I guess you could make fake smart list by attaching a script to a regular folder but it seems likely to be very slow.

What exactly are you trying to accomplish?

I am trying to autoroute files into a complex hierarchy of groups using tags and scripts. The idea is that once I tag a file and drop it in the inbox, the setup will automatically file the file and its replicates where I wish based on the tags.

I need this because the autogrouping feature in DTP isn’t working for my image files nor with my text files that have either programming and technical lingo or are OCR scans (often not in English or with mix languages) of historical documents e.g. 18th century docs in which “vessel” is spelled “veffel”.

My goal is a DRY system in which I set the the metadata for a files exactly once and then I don’t have manage it’s location or grouping ever again.

I found that I can create hierarchies of smart groups by 1) tagging the smart group themselves, 2) setting the node smart group to look only for other smart groups. 3 ) have the leaf groups look only for documents. This creates a hierarchy of smart groups that lead to the specific documents I want collected. Then I can have a scrip just move the contents of a particular smart group wherever I wish. This is particularly useful for clearing inboxes. (Alternatively, I can just toss everything into one big group and then create a virtual organization with the smart tags

I’d like to create the smart groups programmatically because the smart group dialog is very slow and tedious when it comes to tags, mostly because the tag fields doesn’t appear to accept boolean arguments so perforce I must go select each tag individually and the popup is 20+ choices long. It takes over a minute and sometimes longer to create each group assuming I don’t make a mistake. That’s fine for one offs but makings dozens of smart groups is maddeningly slow.

I could do this programmatically much quicker. I could build a nested list with the tags and have recursively go though the list. I could build hundreds of nested smart groups in under half an hour, most of that just typing in the code.

I haven’t really tried the ```

lookup records with tags

This procedure seems very cumbersome and fragile. Cumbersome because of all the maintenance required just to keep it working, and fragile because it depends on a combination of smart groups and custom programming (programming that might not even be feasible, IMO) that could all fall apart if DEVONtech changes something about how smart groups work. Since most of your documents are non-textual (or not easily interpreted as textual) – is DEVONthink the best tool for your catalog? Have you considered Aperture, Bridge, or others?

So, why not use a hierarchy of groups where the groups are included for tagging? For example, in this simple hierarchy, if I tag a document in the Inbox “c” then “c” will get a replicant. If I tag the document “a” and “c” then both “a” and “c” get replicants. Etc.

Smart Groups, as I am sure you know (but just to mention for anyone else reading this) are merely saved searches. There are no documents of any sort “inside” the group.

I don’t mean this disrespectfully, but what you’ve imagined should be possible might not in fact be possible.

No offense taken, I understand that I using an idiosyncratic approach. You are also correct that DTP isn’t the best choice for managing all my image data but it is the best choice for managing all my data, textual, code, images etc combined. Therefore, I must make do.

I know it is possible to programmatically create smart groups because DTP does so with the smart group templates. Unfortunately, the actual searches seem to be encoded in the “data” key of the plist which is unreadable binary. I was hoping that there was an interface I missed.

I tried that and that system works well as long as there as there is only a single instance of the group’s name everywhere in the database, otherwise, I get replicants and often in places I don’t want them. It also prevents me from using tags to describe items in general.

E.g. I have a structure which has several topics and within each topic the files are sorted by media type by tagging (book, paper, clipping). I end up with dozens of groups named book, paper,clipping. If I include those groups for tagging all book groups get replicants of all topics. To use the tagging system, I would have to name each group something like “book Topic A”, “book Topic B”, and so on. That quickly got unwieldily.

Using smart groups and tags I can find only the books of “Topic A”, then move them to the “Topic A Book” group. The system only requires me to “touch” the file once, when I tag it, and it will be properly stored where I wish.

I understand but once I have a set of records within a smart group, it is trivial to move them where I wish with a script. In some cases, living the records in a big pile and just accessing them very smart groups is better. Having smart groups organizing smart groups is just a hat trick.

I am only using smart groups because the exposure of the search functions in DTP in the scripting interface is fairly minimal. If I could script the functionality of a smart group with the efficiency of a smart group, I wouldn’t bother with the actual smart group.

The system I describe works quite well. The smart groups organize the files and then a simple script moves them where I wish. I just wanted to automate its setup. I am a programmer, if I do something three times in row, that triggers the impulse to write code to automate the task. :wink:

I’ll just see if ```

lookup records with tags