Query builder with >

I’m trying to construct a query to search for documents that have a tag like (eg. “”) but when doing that this happens:

If I remove the > it works but then it won’t find that tag… So how can I do this query?

The < and > characters are part of DEVONthink’s search syntax, so I guess it’s not possible to use them the way you want.

You could add Name Lastname to the tag’s aliases and then search tag:Name Lastname, i.e. use the alias in your query instead of the tag’s name.


Ok, I guessed it was something like that but I couldn’t find the documentation. Is there an escape character I could use?


If you have a lot of tags whose name contains these special characters and you‘d like to use the suggested approach please let me know. It takes some lines of AppleScript to make this work (and I think it should be possible to automate the process via a Smart Rule that uses an AppleScript).

The far easier option (as you‘ve already found) would of course be to not use characters that are used in DEVONthink‘s search syntax. But I guess there’s a reason why you want to use them, so please let me know if you need a script.

1 Like

Thanks, so kind of you!
As for now I’m trying to learn JavaScript so that I can get around this problem (I know Python from before so JS makes more sense to me than AppleScript). If you happen to know JS and how it interacts with DT you might know how to add a tag using it? So something like
set the tags of this_item to new_tags
but in JS. Or like how you use
although I cannot find anything similar for tags in the dictionary or elsewhere.

As always, having a look at the scripting dictionary in Script Editor (having set its language selector to JavaScript) might help:

tags (list) : The tags of a record.

Unfortunately, that is AppleScript parlance: a list there is an array here. To be more precise: an array of strings.

So, lets suppose you have a record r. To get its tags, you’d use
r.tags() (yes, that’s right: you use function notation to get properties. Don’t ask me, I don’t know what the Apple guys and gals smoked).

OTOH, to assign to a property, you’d just set it like so r.tags = .... Given that tags is an array, you’d for example do
r.tags = r.tags().push("My shiny new tag")
to add to them. Or
r.tags = ['I only want this single tag]`
to replace/set them to a single value.

<blatant PR stunt>
More on using JavaScript for Automation aka JXA
</blatant PR stunt>

1 Like

It works to add tags if write

const newTags = ['newTag1', 'newTag2']
const tags = record.tags()
record.tags = tags

If I use the suggested

r.tags = r.tags().push("newTag1")

I get no tags at all, probably because of this.

Thanks again!

Cool. I took the code verbatim from one of my scripts. That probably never did what it was supposed to do, because the records did not have any tags before – so only the “assign directly” part run.

What about record.tags = [...record.tags(), ...newTags]?

Looking good! Still all new to JS so have to google this …-thing to understand it :upside_down_face:

That’s the “spread” operator. Cool stuff, and interestingly part of Apple’s JS implementation, although their JXA stuff has not been amenden in the last 8 years. They’re probably using the same JS machine for Safari, so there’s at least a tiny incentive to keep up with development.

1 Like