Add tags to a PDF bookmark script

Hi everyone. I’ve been using this script with good luck. Exactly what I need as I work through thousands of pages of court records and need pull out the bits that matter to my project.

organognosi.com/create-devon … -pdf-page/

But I’d love to be able to add:

  1. Tags to the resulting bookmark entry
  2. A space for notes (right now all I get is the bookmark and no place to write observations on the part of the text I’m trying to create a link for.)

Ideas? THANKS!

http://www.organognosi.com
tell application “DEVONthink Pro”
set nameCurrentPDF to name of content record of window 1
set targetgroup to parent of content record of window 1
set AppleScript’s text item delimiters to {""}
set charFullStop to character -4 of nameCurrentPDF
if charFullStop is “.” then set nameCurrentPDF to characters 1 thru -5 of nameCurrentPDF as string
display dialog “Enter bookmark name:” default answer nameCurrentPDF buttons {“Send bookmark to current group”, “Select the target group”, “Cancel”} default button 2
copy the result as list to {nameBookmark, selectedDestination}
set DEVONthinkPageNum to current page of window 1
set realCurrentPageNum to DEVONthinkPageNum + 1
set DEVONthinkPage to DEVONthinkPageNum as text
set realCurrentPage to realCurrentPageNum as text
set fileLink to the reference URL of content record of window 1
if selectedDestination is “Send bookmark to current group” then
create record with {type:bookmark, name:nameBookmark, URL:fileLink & “?page=” & DEVONthinkPage} in item 1 of targetgroup
else if selectedDestination is “Select the target group” then
create record with {type:bookmark, name:nameBookmark, URL:fileLink & “?page=” & DEVONthinkPage} in display group selector
else if selectedDestination is “Cancel” then
–do nothing
end if
end tell

A little more info, please.

“Tags” is what – the tags of the original PDF? New tags? The original tags plus new tags? Something else?

“space for notes” – you know, the only “notes” a bookmark can have are the Spotlight Comments so that’s the only place the script would put your notes (after collecting them in a dialog). Not exactly a helpful research aid, IMO. Bookmarks have a very precise, but limited, role in annotation.

There are scripts posted in the forum that take a different approach – collect the page-oriented bookmarks into an RTF annotation file where you can keyword and comment extensively. These scripts are usually based on the built-in annotation template. Personally, this is what I do.

Hi Korm,

That’s -exactly- what I’d like to do. Could you point me in the right direction as to how to do this? (When I search PDF annotation or some other similar mix of keywords, I get a sea of responses.)

Thanks!

p.s. But the problem with annotations is that I can’t bookmark specific places in a large PDF file nor can I have more than one annotation files per PDF, can I? The file that I’m working with is 2000 pages long. So I need to slice it, dice it, and refer back to it in many many different ways.

The Annotation rich text note can include a Page Link hyperlink to a PDF, that links to a specific page. Multiple searchable notes can be made within the Annotation note, each with its Page Link to the PDF. I like the Cornell Notes approach to note taking. For each topic I deal with in multiple notes within an Annotation note, I can create a little two column, two row Table. The left cell in the top row describes the topic. The right cell in the second row holds my comments or perhaps an excerpt copied from the referenced document. The left cell in the second row holds a Page Link and searchable summary of the excerpt or comments. (Page Links are available only for PDFs. For other documents, e.g., a WebArchive, a text string copied from the desired location can be used for a Lookup search.)

Although only one Annotation note can be created for a document, that’s not a limitation at all. As above, I can have multiple notes within the Annotation note.

I can also create other rich text notes that are hyperlinked from the Annotation note. These can be notes about the referenced document, or notes about other related references.

IMHO this approach to notetaking is enormously more powerful and flexible than text notes in PDFs, which are only plain text and are not searchable.

And to refer this back to the original post, such rich text notes can be tagged. :slight_smile:

Here’s the script I use (an older version is posted somewhere here, but whatever I wrote before has been OBE, so use this one).

-- Credit: code included from http://macscripter.net/viewtopic.php?id=26498

-- This will put a link on the clipboard to the current page of the currently-viewed PDF in DEVONthink
-- Note that PDF pages are numbered from 0.

-- BY DEFAULT, this script is used by selecting text in a PDF and running the script.  The selected
-- text is put on the clipboard along with an RTF-formated link to that page of that PDF

-- An alternate use is to put only the link to the page on the clipboard, without the selected text

-- To use the alternate, set the propoerty p_linktype to "name

set p_linktext to "text"

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

This script works with PDFs and will do nothing with any other file. Select text in a PDF and run the script. You will then have on the clipboard a rich-text formatted string that includes the text you selected plus a link to that page of that PDF. For example, I selected text in PDF and ran the script. On the clipboard is the text & link. I pasted this into any RTF file (in DEVONthink or elsewhere) and get this:

There’s an alternate use case. There is a property in the script named “p_linktext” which, when set to “name” (quotation marks included) will put this link on the clipboard:

I usually leave this property turned off.

You can put this script into a Keyboard Maestro macro (or Quicksilver or Alfred, etc.) Of, you can put it into the “Toolbar” subgroup of DEVONthink’s Script folders and it can be added to any toolbar. (You’ll need to save the script in “Toolbar”, then restart DEVONthink to make it appear on View > Customize Toolbar…).

Because you have the text + link on your clipboard, ready to be pasted anywhere, you can also accomplish your aim of having multiple annotation files for the same PDF.

The script doesn’t deal with tags, though. Sorry – I wasn’t interested in coding that part of the requirement.

Bill DeVille,
I have PMd you on this, thanks,

I have seen so many post with community members freely offering up scripts. Can someone please explain how to install them on my mac.


What I have been doing is:
Copying the scrip and pasting it to the script editor;
Then I clip the “hammer” icon that complies the script (what ever that is);
I rename the file and save it to the Script Editor folder on my iCloud;
And then i’m lost.

Thanks
Rob

Don’t save it to your iCloud folder.

When you press Save, the Save sheet will appear. Press Shift-Command-G and paste: ~/Library/Application Support/DEVONthink Pro 2/Scripts. Save it there or in a subfolder there. If you’d like to add it as a Toolbar button at some point, save it in the Toolbar folder. It will be available as a Toolbar button after DEVONthink relaunches.

Hi

This is an extremely useful script coz it packs four actions (copy/paste notes from pdf and copy/paste page link) into two simple steps! Thanks very much for the contribution.

I just have one question. I code my documents with 5-digits prefix because they all have a very long file names. So, instead of pasting the entire document’s name as link, may I know how to modify the script to just paste the first 5 characters of the document’s name? I really have no clue in AppleScript.

Thanks in advance
George

Hi

Just figure out how to do it by search on the web. Just add one new line defining a new name based on document’s name and a minor change to another line to replace o_DocName with new_DocName. Thanks again for the script!

set o_DocName to (the name of the content record of think window 1)
set new_DocName to texts 1 thru 5 of o_DocName -- new script