Applescript search predicates question

Can it have multiple conditions - e.g., “Red” and “Boat”, or it can only be an “All” matches “Red”?

The DT AS term search supports operators; whilst the operators are not listed, I would guess it is safe to assume the both AND and OR will be supported.

Blanc, thanks! - I am trying to write this part of a script:

create record with {type:smart group, search predicates:“Austria”, name:“eee”, exclude from search:true }

and having trouble with the [search predicates: “Austria”] part.

how do I structure it so the search predicates finds :Austria" and “Russia”?

Ah, I had misunderstood you; play with this:

create record with {type:smart group, search predicates:"any: all=Austria all=Russia", exclude from search:true}

THANK YOU! :slight_smile

1 Like

@cgrunenberg: I’ve never seen anyone apply an exclude from search to a smart group. While it appears to be a valid option, it doesn’t appear to work with a search like apple scope:selection.

Actually, two things…

  1. AND is assumed in a multiword search.
  2. All is assumed when no search prefix is specified.

So the search could merely be Austria Russia.

2 Likes

I’m pretty sure that just a day ago I read a response from you saying something along the lines of “it isn’t necessary but demonstrates awareness for the scope”. Damned if I can find it though; perhaps it was a dream.

I do feel it’s better form to use search prefixes and be more focused in searches, just as I feel smart rules should be more specifically targeted. However, I was just noting if people just type in search terms, the All criterion is the one that’s used.

1 Like

This excludes only the smart group, not the items it might find.

Gotcha. Thanks.

Dear all, thanks you so much for the help (and, awesome to have 3 gurus here :slight_smile:

I did build a script and it is working for creating a new smart group (in this instance, with name and search predicates taken from selected text, I also have a version with a dialog).

tell application "DEVONthink 3"
	
	-- next iteration set theName to text selection, save to current group’s parent
	
	set theRecord to the selected record
	
	set theParent to the parent of theRecord
	
	set theName to ""
	
	set theName to the selected text of think window 1
	
	set theSearchPredicate to "docKeywords:" & theName
	
	create record with {name:theName, type:smart group, search predicates:theSearchPredicate, exclude from search:true} in theParent
	
end tell

What I am struggling right now is how to create the smart group inside the same group as the record I am copying the text from. If I don’t do anything, it will create the new smart group in the global inbox. How do I point to the location I want? (you can see my incorrect attempt in the script)

1 Like

Please post code enclosed in 3 backticks (```) above and below the code (I’ve modified your post).

Whilst I cannot explain why, you cannot set theRecord to the selected record, and instead need to do what I have done below. Also, you need parent 1 rather than parent, because items can have several parents. It is prudent to use application id "DNtp" rather than application "DEVONthink 3" as the former will work after installing the next major release, whilst the latter will not. Finally, there is no need to set theName to "" before setting it.

So your script becomes:

tell application id "DNtp"
	
	-- next iteration set theName to text selection, save to current group’s parent
	
	set theRecords to selected records
	
	set theRecord to item 1 of theRecords
	
	set theParent to the parent 1 of theRecord
	
	set theName to the selected text of think window 1
	
	set theSearchPredicate to "docKeywords:" & theName
	
	create record with {name:theName, type:smart group, search predicates:theSearchPredicate, exclude from search:true} in theParent
	
end tell

You may want to add error catching, so bringing up a message if no text/item is selected, for example. I’ve tested the script above, and it seems to do what I understand you are trying to do.

Thanks Blanc!! - I will do my best to add the 3 backticks - thanks for doing that!

About setting theName to “” - I also thought so, but when I remove that statement the script fails, don’t know why…

It works here as posted (by me).

You can use selected record 1 if you only want to process the first (or only) selected record.

1 Like
  • What is the error you see?
  • Do you have text selected in the view/edit pane?

Yep, Blanc and Jim, it works when I run Blanc’s script (which omits the set to “”) - so all fine and dandy!!

I am sooo happy with the new script, it magnified my productivity 1000% - thank you both (and Christian as well).

So what the script is doing for me, is, in my soon to be blog about stamps, I am creating hundreds of groups for the topics. I have thousands of stamps (png) indexed in a DT database, exported from Adobe Lightroom with VERY extensive lightroom keywording. I export the files using Jeffry Friedl’s plugins. DevonThink awesomely knows that the png have keywords, and converts these to tags if I want. So I have files with both keywords AND tags. If I add more keywords to the images (much easier to do in Lightroom, and also because I might want to image-process and re-export the files). So from Adobe Lightroom to indexed folder in DT. In DT, I created these “topics” folders that contain query-based stamps AND also literature, my own notes, etc, some because I created the notes right there in the folder, others because the query is matching the search term (e.g., “Fisheries”) in literature that I have in older folders,

Mike

2 Likes

BTW, I am also using a defined vocabulary, and a structured png file naming.

1 Like

You would have thought I might have figured that out myself. Thanks Jim, that will streamline things a little more when I’m writing test code.

2 Likes