Item links in DT3

According to the DT Help Document, DT supports Item links with some extended
parameters, one example is to limit a search inside a file by

x-devonthink-item://<textFileID>?search=iPad%20Pro

This syntax is supported in DT2, and documented in the Help documents of both DT2 and DT3. But in DT3, percent-encoded chars seem to be incorrectly parsed, only alphabetic characters work.

I didn’t know about in-file searching via URL commands! Bugs aside, what do you use it for? It seems handy…

Confirm that I am seeing this too.

Didn’t know about this either, but love the idea of using it to link to a specific part(s) of a document, such as a subheading. Paired with a script, added to the toolbar, and it’d be pretty useful:

tell application id "DNtp"
	try
		if not (exists think window 1) then error "No window is open."
		if not (exists content record) then error "Please open a document."
		
		set find_this to the selected text of think window 1 as string
		set itemURL to get the reference URL of (item 1 of (selection as list)) & "?reveal=1" & "&search=" & find_this
		set the clipboard to itemURL
end tell

*note, my script doesn’t replace spaces with %20 yet… (I hate doing string replacement in applescript).

2 Likes

As noted in your Support ticket, that is not the correct syntax.

The correct syntax for this is x-devonthink://command?parameters

This is covered in the built-in Help > Documentation > Automation > URL Commands.

I read the documentation and I have it open here right in front of me. Still, I have no clue as to how to create a link to a markdown file and issue a command for it to search for a specific word. All the commands appear to be directed towards creating a new file.

The other syntax worked just fine, though.

e.g. x-devonthink-item://DFC90E80-7832-466B-8866-DC199F2605D7?reveal=1&search=individual

This works:

x-devonthink://search?query=test

x-devonthink-item://DFC90E80-7832-466B-8866-DC199F2605D7?reveal=1&search=individual

That is not a valid form of the URL scheme. You cannot have more than one command in the URL.

This works as expected…
x-devonthink-item://D2160D98-09AE-4C5C-8DCA-02F6E9624D0D?search=expectations

…though @cgrunenberg would have to assess if the Search inspector should reflect the search terms provided in the URL. Currently they do not. Also, the search hits aren’t detected to move from highlight to highlight.

Perfect. This is simpler and works as expected. :upside_down_face:

x-devonthink-item://D2160D98-09AE-4C5C-8DCA-02F6E9624D0D?search=expectations

It would be nice, of course, if one could move from highlight to highlight. :wink:

It would be nice, of course, if one could move from highlight to highlight.

You already can when using the in-document Search inspector. Not only by clicking the results but also the Next and Previous Highlight buttons in the Navigation bar.

Sure, ⌘G and ⇧⌘G are my amongst my best friends. I meant of course after following the link. All found itens are highlighted, but you can’t move through them.

tell application id "DNtp"
	try
		if not (exists think window 1) then error "No window is open."
		if not (exists content record) then error "Please open a document."
		
		set find_this to the selected text of think window 1 as string
		set itemURL to get the reference URL of (item 1 of (selection as list)) & "?search=" & find_this
		set the clipboard to itemURL
	end try
end tell

This would be the corrected form of the applescript, I believe.

But this example is just a copy from the Help documentation of DT3, place: Help > Documentation > Automation > Item Links, please see Example:

The same are documented in DT2 and DT3 !! This syntax do work perfect in DT2 !! And also somehow work in DT3, so the example above still work in DT3:

x-devonthink-item://<textFileID>?search=iPad

but percent-encoding is not supported any more.

That’s why I call it bug, it is just a byproduct after update, suddenly a clearly documented and implemented feature become different.

I find it very handy to use this syntax in Markdown files, in order to jump to a precise location. I hope it could be kept valid in further versions.

This is a useful feature. If we open a PDF file and browse to page 10, then right click on that page to open the DT context menu, we will find a function Copying Page Link, then paste it as a plain text, we will see something like:

x-devonthink-item://83D64686-82E1-4281-A688-B7EBF56FB345?page=10

We will see a string end with ?page=10, that is exactly that page number we have previously opened. So we can modify it to any number in order to jump to another new page number.

We can insert the whole string as a hyperlink in a RTF/TextEdit file, or like me, use it in Markdown to jump to a specific page of a pdf file, like

[note: jump to page 10](x-devonthink-item://83D64686-82E1-4281-A688-B7EBF56FB345?page=10)

This syntax actually enables users to locate any place, not just a page number !!

Say we are reading a pdf file, and find a interesting keyword we want to locate, e.g. the author name “Max Plank”, we can do this by

[note: search author name](x-devonthink-item://83D64686-82E1-4281-A688-B7EBF56FB345?search=Max%20Plank)

This will automatic search string “Max Plank” inside the pdf file and highlight the found locations.

Going further, if we provide a unique text snippet to use it as anchor, this will exactly locate any place we want !!

Note: the empty space has to be encoded as %20.

Clearly, the easiest way to achieve a unique marker is to use a longer string, e.g. a sentence, so we have to combine them using percent encoding, like %20.

What I mention in this report is the following issue.

Percent-Encoding was supported in DT2, but not now in DT3. So in DT3, we have to replace it

[note: author name](x-devonthink-item://83D64686-82E1-4281-A688-B7EBF56FB345?search=Max)

This will give us more search results, so we have to jump by clicking Next Highlight tediously. Schade !!

Thanks. I’ve used item links with page numbers in the past, but not searches. It does seem like it could be useful.

However, the link above, with two commands (?reveal=1&search=individual) does work…

What doesn’t seem to be working is a search example from the manual, that contains a space coded as “%20” (e.g. search=iPad%20Pro).

@cgrunenberg would have to address percent encoded URL commands in Markdown.

PS: The version of MultiMarkdown in DEVONthink 2 and 3 are not the same.

It’s not an issue of the encoding, it doesn’t seem to work together with revealing.

[test](x-devonthink-item://16F7228D-2BAC-4950-9604-0A4B3F1CA9F1?search=dropbox) --> works
[test](x-devonthink-item://16F7228D-2BAC-4950-9604-0A4B3F1CA9F1?search=dropbox%20sync) --> doesn't work

I just noticed it’s not working in a browser either.

3.0.1 should fix this.

2 Likes

confirmed, %20 is now supported, thanks!

1 Like