useful keyboard shortcut for making RTF notes about PDFs

I am still struggling to find an optimal way to handle my research and reading. I was using Acrobat to mark directly on the PDF, but decided that if I wanted to take full advantage of DevonThink’s searching in its current form I should use Bill’s suggestion on making RTF notes.

One of the major issues I was having was quickly copying the page link of a pdf. I could only find the option in the contextual menu when right clicking on white space in a PDF document so I couldn’t use system wide keyboard shortcut manager in System Preferences. Instead I created a QuicKeys macro to right click on the document window and select copy page link. I have this mapped to my f4 key, and have my PDF displayed in one window and my RTF note in another. Pressing f4 copies the page link but doesn’t move my cursor so that I am able to immediately insert it with a cmd v.

This could certainly be applescripted, but AppleScript is a foreign and hideous language IMO. I’m actually reading an ebook pdf right now on Ruby so that I can use MacRuby with scripting bridge to do automation.

Hope this tip is of use to someone.

Indeed it is … but here’s an execrable script that will put the page link on the clipboard, ready to paste 8)

-- this will put a link on the clipboard to the current page of the currently-viewed PDF in DEVONthink
-- Note that pages are numbered from 0
tell application id "com.devon-technologies.thinkpro2"
	if the current page of think window 1 ≠ -1 then
		set the clipboard to (the reference URL of (the first item of (selection as list)) as string) & "?page=" & the ((current page of think window 1) as string)
	end if
	--else the current window is not a PDF
end tell

[size=80]Feb 1, 2012 Update: the above script creates a plain-text link. The script posted a few posts down below creates a prettier RTF-formated link[/size]

You are awesome, thanks, this helps a bunch

edit: minor detail, I’m using Scrivener to write and pasting the URL doesn’t generate a clickable link whereas if I copy the page URL from the contextual menu it does.

Works fine in DTPO RTF though.

Thanks again

Yes, in Scrivener you need to edit links in this panel, and use the “No prefix” setting. (There’s probably a keyboard way to do this, which I’m not aware of.)

Yes, I agree, that’s how you should edit a link to a DTP item from a Scrivener rich text field. How to optimise DTP to get a clickable RTF link without using the contextual menu is outside of my scope of knowledge, but isn’t Edit/Copy Item Link (or Ctrl-Opt-Cmd-C) the same exact thing as what is in the contextual menu? It seems to work identically for me. I get an RTF readable text that is hyperlinked to the x-devonthink-item URL when using that, and it pastes fine into Scrivener. Perhaps I’m missing something though, I’m only a basic level DTP user.

If you are stuck with a raw x-devonthink-item URL, you may find References to be more convenient, as you don’t have to use the add link panel and set it to no prefix, you can just paste the URL into the reference pane. Click the + button in the Document or Project References panel, select “Create External Reference”, use the Description column however you see fit, and then paste the x-devonthink-item link into the URL field. To activate it in the future, double-click the icon.

Matter of taste of course, whether you want them in the text or in a list on the side.

Thanks for coming over from Scrivener support and giving us an update, Ioa

The OP was looking for a PDF page link, which appends a page reference to the standard DEVONthink document reference URL – this is different from the Copy Item Link link that references the entire document, e.g.:


Now I realize the code I posted above creates a plain text link, not an RTF-formated link – as opposed to the RTF-formatted link that Edit > Copy Item Link produces.

The following version of the script fixes that, and puts a clickable RTF link on the clipboard with the name of the PDF and a page link. (For flexibility, there is a switch hardcoded in this version to create a page link whose name is either the selected text in the PDF or the document name.)

-- make RTF link in clipboard
-- with reference to
-- this will put a link on the clipboard to the current page of the currently-viewed PDF in DEVONthink
-- Note that pages are numbered from

-- choose the type of link and set the following property value; "text" is selected text; "name" is document name
-- set p_linktype to "text"
set p_linktext to "name"

tell application id "com.devon-technologies.thinkpro2"
	if the current page of think window 1 ≠ -1 then
		set o_Page to " (pg. " & the (((current page of think window 1) + 1) as string) & " )"
		set o_URL to (the reference URL of (the first item of (selection as list)) as string) & "?page=" & the ((current page of think window 1) as string)
		if p_linktext = "name" then
			set o_Text to (the name of the content record of think window 1) & o_Page
			set o_Text to (the selected text of think window 1) & o_Page
		end if
		set o_HTML to quoted form of ("<font face=\"helvetica\"><a href=\"" & o_URL & "\">" & o_Text & "</a></font>")
		do shell script "echo " & o_HTML & " | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf"
	end if
	--else the current window is not a PDF
end tell

Korm, thanks again. Cheers!

Hello all,
I’ve got a related question: Instead of making RTF Notes, I wanted to try and use the anotation template that ships with DTPO.
The template retrieves the link to the document, but not to the exact location. How would I go about getting that link, using the script that korm has so kindly shared?

Thanks for any help …

It’s not possible to find “exact location”, but it is possible to find strings. IOW, if I have a PDF with a text string “Situational rather than abstract” then this link will open that PDF and find that string:


Here’s the script that creates the link. Obviously, the link will find the first instance of the string. Use your keyboard to find more instances. The link created here is a plain text link (not a pretty RTF link). This is an old script of mine, and someday if I have time I’ll pretty it up to make RTF links. Finally, the best use of this is not so much to search for strings you want to annotate, but to use the link to find unique “anchor” text near to where you want to open the PDF. For example, this search string is just a snippet of text, but it’s close to where I want to jump in the PDF.


Here’s the script:

set MaxLen to 1000

tell application id "com.devon-technologies.thinkpro2"
	set theSelection to selection
	if theSelection is {} then error "Select an item, please"
	repeat with thisItem in theSelection
		set theCitation to selected text of think window 1
		if theCitation is "" then error "Select some text, please"
		if length of theCitation is greater than MaxLen then error "That selection is longer than " & MaxLen
		set theCitationEncoded to (do shell script "php -r 'echo trim(urlencode(" & "\"" & theCitation & "" & "\"));'" as string)
		set the clipboard to the reference URL of thisItem & "?search=" & theCitationEncoded
	end repeat
end tell

-- example
-- x-devonthink-item://B03F511C-E9EA-4228-A4B3-DB047E269CD8?search=%E2%80%9CGoldie.%E2%80%9D+The+other+fish+you+name+%E2%80%9CGreenie.

Thanks for this, Korm. It will be very useful.

My initial question was probably badly phrased: I was looking to use your previous script (although this one may be more handy) INSIDE the existing “Annotation” template.

Use case: when I select some text in a pdf or any doc, and press the anotation shortcut (IIRC ⌥⌃⌘A) then the template opens, and instead of having the link to the document, I have a link to the page (or, with your latest script, the approximate section in the page)

I’ve tried looking at the annotation template and I confess I’m completely baffled by the structure of scripts and packages …