"Scope" parameter not working in URL Scheme

I’m constructing a simple search URL and the scope parameter seems to be ignored.

I’ve copied the item link (the scope is to be a group, in this case) and constructed the following URL:

x-devonthink://search?query=name:*11-28*&scope:AC8EAD15-712B-4BC8-9E0C-DC6FFC379547

Properly escaped that’s:

x-devonthink://search?query=name:%2A11-28%2A%26scope:AC8EAD15-712B-4BC8-9E0C-DC6FFC379547

The search performs on my active database. I get results. But it’s not limiting the search in any way.

I’ve read through countless threads about this seemingly simple construct and yet I can’t get this working completely. In one thread there was mention of the scope not working when clicked outside of DT. So I used it inside DT. No luck.

I need the scope to work. Any thoughts? Am I missing something glaring?

URL scheme structure is:

x-devonthink://<command>?<parameter=value&parameter=value&...>

So, changing the colon to an equal sign seems to limit the scope (on iOS). However, as you found out, it doesn’t limit the scope on DevonThink 3 (macOS).

Why are you constructing a URL for searching?

@BLUEFROG I have a DT directory (group) containing hundreds of image assets that are specific to use on a given week of the year. The image assets are all named (prefixed) with a date that identifies the given week’s usage (in the above example it’s “11-28”, hence the 11-28 search).

These image assets run on a three year cycle, making the complete circuit 52 searches x 3. So in addition to each asset’s name, each year’s assets reside in a separate folder. Thus, each week would require my looking up this week’s prefix/search (it’s not intuitive; it has to be looked up), entering it in search manually, and then limiting the scope.

With an Excel spreadsheet (later imported into DT as a sheet) I can quickly assemble the relation between the given year’s date (aka the search term) and the given year’s folder item link, and then construct the search URLs once. Then it’s easy street: just look for this week’s entry (constructed neatly in and Excel column as “a-week-01,” “a-week-02,” “b-week-01,” and so on) and click the search to find this week’s assets.

@unlocked2412 Are we saying this can’t be done? Seems like a glaring omission. Searching my entire database is probably my least frequent scenario. But even for those who do it frequently, it’s the broadest, least-granular option. Not a great feature for URL parameters to exist but be so fundamentally limited. ??

@unlocked2412 Oh, and using = for the delimiter on parameters results in a failed search for me.

= strips the wildcard asterisks in DT. FYI.

scope is not a parameter in our URL scheme.
Also, the search field doesn’t support item links for a search scope.

It would be a great feature. As one can do it manually with a manual selection, would be great to be able to automate it. My 2¢.

EDIT Wait, I thought scope had “selection” or “database name”.

selection or a database’s name are valid search scopes.

As I said, scope isn’t a parameter of our URL scheme, but you could try something like this…

x-devonthink://search?query=luthier%20scope:"guitar%20gear"

The scope is part of the query, just not a separate parameter.

I believe the hurdle for me would be specifying the path in the query. Each year’s files reside in a subdirectory that is named the same as the others, but one is not at the same depth.

Here’s what I managed:

Using Excel functions I constructed a Keyboard Maestro URL that tacks on as its “value” the UUID of the folder and the search term.

A sample trigger url looks like this:
kmtrigger://macro=03D29691-35CD-4383-8944-56E0E507253A&value=*02-13*,AC8EAD15-712B-4BC8-9E0C-DC6FFC379547

If you notice, the “value” contains the search term and the UUID —comma separated. This leverages Keyboard Maestro’s functionality which will read a comma-separated value as an array, thus allowing “TriggerValue[1]”, “TriggerValue[2]”, etc. Then I can pass those off to the macro which…

  1. Sets the search term var to
    x-devonthink://search?query=name:%TriggerValue[1]%%20kind:image%20scope:selection
  2. Sets the search scope var to
    x-devonthink-item://%TriggerValue[2]%
  3. Opens DevonThink
  4. Opens the database I need it to (just in case)
  5. Pauses until DevonThink is open and frontmost
  6. Opens a new window
  7. Opens the scope URL which targets and selects the folder in question
  8. Pauses for a few seconds and…
  9. Opens the search URL which performs the scoped search. :slight_smile:

Thanks all for your input.
(Aside: Keyboard Maestro is just an amazing piece of work. Get it.)

DevonThink To Go 3 Help, says:

Searching

Search your databases.

search:
Search DEVONthink To Go and show or retrieve the results.
The command takes the following parameters:

query:
The query to use for the search.
scope:
The UUID of the database or group to search. Optional; if not set DEVONthink To Go > searches all databases.

From your comment, I’d assume macOS and iOS have different URL schemes. Is that correct, @BLUEFROG ?

I believe the quotes around guitar%20gear should be URL encoded. Then, it works great on macOS. Thank you, @BLUEFROG !

That’s correct and scope in the DEVONthink To Go help is referring to choosing one of the three options available under the search field.

1 Like

It should also work with normal quotes. That’s what I tested it with in DEVONthink.

And you’re welcome :slight_smile:

Yes, of course. It works in DT. I just meant that your example should be URL encoded.

Like this:

x-devonthink://search?query=luthier%20scope:%22guitar%20gear%22

(Quotes aren’t allowed in URLs, I think).

Actually, I ran the URL from Firefox and Safari with the quotes intact and it worked in both cases. However, percent-encoding is a better habit in such cases. :slight_smile:

FWIW, Keyboard Maestro didn’t recognise it as a valid URL.

Keyboard Maestro is quite finicky about URL structure. The only way I could get it all to work was to chop the URL up in sections, run an URL encode filter on some of them, and then assemble them into another, final variable which I then fed to KM to open. It did so happily.

I would have saved myself quite a bit of aggravation had I thought of that first rather than last. :man_shrugging: