Create link to line?

I have a lot of long PDFs in a database. Sometimes I need to stop work in the middle of one of those long pages, and I’d love to create a kind of bookmark or link that I can invoke the next time I open up DT3 that will bring me right back to that very line in the middle of the long PDF. “Copy Page Link” only brings me back to that one continuous page that might represent 20 or 30 pages if I had paginated it.

The workaround I use now is to copy a long-enough text string from that page and paste it in another document … then when I when I later re-open DT3, I copy and paste that text string into the DT3 search bar. But this feels kludgy to me. Anyone know a more elegant way to do this?

Thanks in advance.

No, there is no way to link to a specific line or place in a line.
You could create an annotation, e.g., a Note annotation, and jump to it from the Document > Annotations inspector.

You could use this as an alternative. Select text to form a unique string and fire the script. It will copy the item url and attach a command for it to search for the string you selected. It works pretty well for me for plain text files. Eventually I use for PDFs as well.

tell application id "DNtp"
	set theRecord to (content record of think window 1)
	set theSelection to the selected text of think window 1 as string
	set theSelection to my replaceText(theSelection, " ", "%20")
	set theURL to get the reference URL of theRecord & "?search=" & theSelection
	set the clipboard to theURL
	
end tell

on replaceText(theString, old, new)
	set {TID, text item delimiters} to {text item delimiters, old}
	set theStringItems to text items of theString
	set text item delimiters to new
	set theString to theStringItems as text
	set text item delimiters to TID
	return theString
end replaceText
3 Likes

Hi Bluefrog,

Since I haven’t been able to figure out how to Annotate a PDF, or search for a highlight, I created two Keyboard Maestro macros, one to save a search string, enclose it in quotation marks, and paste it into a file I call “Last Page”, and which I keep in my Global Inbox.

The second macro opens that “Last Page” in my Global Inbox, copies the text, and searches for it.

It works very well, and very quickly.

1 Like

Hi Bernardo,

Just saw your script after I posted my Macros. Thanks for that! Much appreciated.

Roger

1 Like

Wow, it works with PDFs!

I used a script from user korm but at some point it stopped working (I think after a DEVONthink update) and I couldn’t fix it. The difference between yours and korms script is the escaping of characters, newer DEVONthink versions doesn’t seem to need special characters escaped anymore.

Thanks a lot!

1 Like

This is all covered in Help > Documentation > Documents > PDFs.

Thanks Bluefrog. I’m sure it all makes sense to you, but after going through Help over and over, I still cannot figure out how to annotate something in a PDF that I can search for later. For instance, I can create a Note or Annotation inside the PDF, but can’t figure out how to search for it. What am I missing?

1 Like

Hi Bluefrog,

My problem is not that I haven’t figured out how to annotate or highlight or link. My problem is that I haven’t figured how to SEARCH for an annotation, highlight or link. The Help pages - which I have gone through a lot - do not make it clear. So if there is a way for me to create a searchable “bookmark” by annotating, highlighting or linking, I’d love to know what it is.

Again, what I’m trying to do is find a simple way to add something to a non-paginated PDF document to show where I left off, so that the next time I open the app, a click or two will get me back to the place where I left off.

This modified version of Bernado’s script creates a bookmark and asks where you want to store it. When you want to go on reading select the bookmark and open it’s url.

tell application id "DNtp"
	set theRecord to (content record of think window 1)
	set theSelection to the selected text of think window 1 as string
	set theSelection to my replaceText(theSelection, " ", "%20")
	set theURL to get the reference URL of theRecord & "?search=" & theSelection
	#set the clipboard to theURL	
	set theName to (name of theRecord) & " <- stopped here"
	set theBookmark to create record with {type:bookmark, URL:theURL, name:theName} in display group selector "Create Bookmark:"
end tell

on replaceText(theString, old, new)
	set {TID, text item delimiters} to {text item delimiters, old}
	set theStringItems to text items of theString
	set text item delimiters to new
	set theString to theStringItems as text
	set text item delimiters to TID
	return theString
end replaceText

Unfortunately this

isn’t true, so if it doesn’t work try again with something else selected.

1 Like

Hi Pete,

Thanks for checking this out. I think I’ll stick with the Keyboard Maestro macro. It seems to work well enough. I appreciate your help, though.

Roger

Maybe someone can help me out with what perhaps is a fundamental misunderstanding on my part on how to compile a script.

I did a copy paste both to Script Editor and to Script Debugger and I get this error when trying to compile the script with either app. It’s not the first time this has happened so it probably is something I am doing wrong or not understanding. Thoughts?

I’m not seeing any issue with Script Editor here.

Well oddly enough - I have two Macs side by side.

On my new Mac I get the response above.

If I do the same exact thing on my older Mac (still running current version of Catalina) it works fine.

What could be configured differently about one of the Macs to cause this?

No idea on this, but I’d start by rebooting the machine.

OK that fixes it - for the other script causing problems too.

I try not to reboot the machine given that there are several user accounts active with others logging in - but clearly that is necessary periodically.

For anyone who uses Hook, you can generate unique tokens through Hook that you then add as annotations within records in DT (e.g., PDFs, RTF, plain-text). You can then invoke Hook with the token on your clipboard and Hook will bring you not only to the document with the associated annotation, but to the annotation within the document itself.

Some more info in this thread over on the Hook forum:

EDIT: For clarity, this only works with Skim and won’t bring you to the location in the PDF within DT.

1 Like

Thank you @pete31 and @Bernardo_V - very helpful script

Maybe @BLUEFROG can lend some insight here, but I think the expected functionality is that a search within DT as follows should at least give you a list of the records that have annotations applied to them:

Trouble is not only that this doesn’t appear to work (at least, for me, the PDFs I’ve annotated within DT aren’t showing up and other PDFs that seemingly contain no annotations do show up). Moreover, unless I’m missing something, it doesn’t appear to be possible to search the content of a note annotation from within DT. Again, hoping @BLUEFROG can clarify…