QuoteHighlight&Annotate script

Dear all,
I’ve just wrote a simple script to automatically highlight and export quotes while reading a rtf or pdf document, so to have them collected all toghether in a separate document with clickable links to the source for every quotation. This solves my problem to have a way to automatically highlight and collect the salient parts when reading a paper, to have them listed for a simpler and faster review, and to be able to jump for each of them, directly to the original source page of the quotation, without doing manually the copy/paste operations from the source to the summary document. I hope that can be useful to other users that read several scientific papers every day and need simple and fast a way to summarize and track back.

To use the script, select the text you want to quote from a rtf or pdf document then just execute the script from “menu Data > New from Template > QuoteHighlight&Annotate” or by typing Cmd-Alt-Q (“Q” stands for “Quote”): a record called “Quotations&Annotations:” will be opened (or created if it doesn’t exist yet, in the group named “Quotations&Annotations” ) and the selected text from the source document will be appended as a new quotation at the end of the record, toghether with an hyperlink to its source and a slot where you can type your annotations.

Unfortunately I’ve found that highlight is scriptable only for rtf source documents, content attribute scripting seems not to be supported at the moment for pdf documents, so this script automatically highlight quotations only in rtf sources not in pdf (I have to do it manually for every citation), but it helps to easy export quotations and links for both.

I’ve wrote this adapting the original ‘Annotations’ script (by Eric Böhnisch-Volkmann and Christian Grunenberg © 2009 DEVONtechnologies, LLC), and with the help of many code fragments found around the forum (I haven’t kept track of authors while surfing, so please forgive me and add you your own credits if you recognize part of the code from some your post).

Install the script package “_QuoteHighlight&Annotate___Cmd-Alt-Q.templatescriptd” in ‘~/Library/Application Support/DEVONthink Pro 2/Templates.noindex’.

Feedback and improvements are welcome!

The following is an example of a couple of quotations obtained selecting some text and running the script for each selection:

Quotation, Page 1:
The role and importance of interaction structure is a central yet unresolved issue in mathematical epidemiology (1). At the broadest level, the issue is straightforward: clearly not all people interact equally with all others;
Link: x-devonthink-item://32CD0658-64F9-4A49-87F6-F30AB3A515DD?page=0
Annotation:
(type here your annotations)

Quotation, Page 5:
Aside from highlighting the importance of stochastic, rare events, the multiscale and resurgent properties of epidemics in our model suggest that population structure itself can act as a kind of control.
Link: x-devonthink-item://32CD0658-64F9-4A49-87F6-F30AB3A515DD?page=4
Annotation:
(type here your annotations)

Here it is the downloadable zipped package of v1.0 (but v1.1 is coming soon RECTIFICATION: I hope it will come soon, but I’m very busy in these days ):
_QuoteHighlight&Annotate___Cmd-Alt-Q.templatescriptd.zip (152 KB)

This is brilliant. I can’t thank you enough for taking the time to put this together and share it.

Very nice and useful script.

Two problems I have run into (w/ .rtf as source document):

  1. If the name of the source document is changed after creating a Q&A document, trying to create a second Q&A document results in the original name of the source document being inserted.

  2. If a Q&A document is deleted (and deleted from the trash) invoking the hotkey with the source document foremost and with text selected results in the insertion of the quote into the source document itself rather than creating a new Q&A document.

? any insight into the reasons for the above behavior - or possible corrections ?

@Matty: Thanks Matty!! :slight_smile:)

@rpor:
thanks for debugging! Unfortunately the script hasn’t (yet) a robust error checking, it is just a quick&dirty solution I’ve written for my personal use, but I’ll post soon a more robust version (I’m working on now), taking into account the two problems reported…

G

This is just awesome. I have only one, possibly impossible request: when reading documents in fullscreen, invoking the script causes the document to revert to normal size. Any way to avoid that?

A work-around is to tell system events to press the keystroke combination currently assigned to Format > Highlight.

Suggestion: when I write annotation scripts I capture the original URL for a document (e.g., the site from which the PDF was printed to DTPO) and then display that URL in the annotation document. This makes up for the lost URL that happens when you insert the annotation document URL into the URL field of the annotated document, and gives the reader a clickable link to the source site.

I can’t tell you how much I love this script :smiley: . As I am working on my Literature Review for my dissertation, this is so handy and will make the workflow using Devonthink much smoother.

I did have one request, but since I am not at all familiar with Apple Script, I am not sure whether this is possible or not and, if it is, how to do it. Currently, there is a template in the Education folder that adds an Endnote Reference (whichever is currently selected) in a new rtf document window. What I would love to happen is to have your template incorporate the script from that one, so it would pull in the EndNote reference into the same window/rtf document with the quotes and annotationsin, in addition to the things it already does. I tried opening both applescripts and just copying and pasting the endnote script into the annotate one, but it did not work, which I am not surprised about since I have never worked with scripting at all before.

Thanks in advance for your response!

Hello my friends,
I’m back again. Sorry for the delay, but I was away for many days. I read the new comments: thanks for all the suggestions, I’m very glad that the script has been useful, in the coming days I will resume the development of the new more refined version, and I’ll try to implement all the request.

Guido

Thanks for this great script !

I don’t know whether it would be impossible/difficult but here is my suggestion/request.

While I am doing research I am usually browsing many pdf’s at the same time. I don’t keep a separate annotation document for evey pdf, rather I keep one for every project which has annotations/notes/clippings from different files and I insert links to related pages of the related documents where possible. So I was wondering if it would be possible to implement this sort of a scenario.

I guess it boils down to the following: would be possible to append all quotations from all documents to a single file rather than creating a different annotations file for each pdf.

Cheerito,

Ugur

Hi Ugur,
I complete agree with you. A single document to summarizes all the citations from different sources would be very helpful me too. In the next version of the script I’ve already scheduled to add the possibility for the user to define an “active” summarize document that will receive quotations from different source. Unfortunately I’m working on it intermittently, so it is taking much more time than expected :frowning:
Guido

@gts

One of my favorite templates!

To simplify the display in the quotation/annotation document of the link back to the original document I made this adjustment to your script in the “Append Quotation” section:


make new paragraph with data (return & "Quotation: ") at the end of text of think window 1
make new word with data ("Page " & the theCurrentPageNumber & return) with properties {URL:theQuotationFullUrl} at the end of text of think window 1

The display is thus:

Rather than:

Just a personal preference for text over ugly DT custom urls. :wink:

I have found this script to be extremely useful and have incorporated korm’s adaptation into the original script.

My knowledge of Applescript is extremely limited. I’ve tried making some further adaptations to suit my needs but haven’t been successful as yet.

How would one go about modifying the script to:
1.Place the Q&A document in the same folder as the original

  1. Name the Q&A document so that the name of the original document comes first followed by “Quotation & Annotation” so that the 2 documents are adjacent when viewing the group contents sorted by “Name”
  2. Use another type of mark up (i.e. red underline) rather than a colored highlight
  3. Reference the Q&A document from its PDF source document

Thanks in advance for any suggestions

Hi rpor,

I have modified the template and marked all modifications with “MODIFICATION” in the script.

Done.

To the best of my knowledge, it’s not possible to specify the underlining color, but the script still underlines the selection.

Isn’t this what the URL in the original document is for?

Greetings
Patrick
_QuoteHighlight&Annotate___Cmd-Alt-Q.zip (27.2 KB)

Guido, thanks a million for the useful script!

Have you had a chance to change the script to allow to choose an “active” document for keeping all quotations and annotations together?

Many thanks Patrick for your modifications - perfect!

I’m back again: trying to use this template, but getting the following error message when I apply it to a highlighted PDF:

The variable theQuotation Text is not defined.

I’m sure I’ve done something wrong, but I’m very unsophisticated about scripting etc. Can anyone steer me in the right direction?

Thanks,
HD

PS: I’ve tried installing the “Merge Highlights into RTF” script from the extras, but apparently it doesn’t work on PDFs. Is there a fix for this?

Which version of the template are you getting the error from? There are several versions discussed in this thread. The scripts discussed here require text to be selected in a PDF and will throw an error message if no text is selected in the PDF window that has the focus when the script is run.

“Selecting” text and “highlighting” text are two different things, as you know. These scripts don’t work on highlights. :confused: See your next question.

No.

It is not possible for DEVONthink scripts to access PDF annotations (PDF highlights are annotations). Several of the posts, above, discuss this shortcoming. The “Merge Highlights (rich)” and “Merge Highlights (text)” scripts are only for RTF files that contain highlighted text and cannot work on PDFs. (In fact, the script explicitly skips anything that’s not an RTF file.)

First of all, thank you for all the helpful advice you give, from which I have benefited greatly over the years!

I used the most recent version of the script. I have just run it on a selected passage rather than a highlighted passage, as you suggested, and it worked fine (I was using it on highlighted passages because that is what it’s called). The difference is that it is possible to highlight a number of passages at once; is it possible to select more than one passage at once? (I tried the standard Mac thing of holding down the command key to select an additional non-contiguous passage, but it didn’t work.)

In other words, what I am trying to do is read an article, marking passages as I go, and then have all the marked passages combined into an editable document. Is that in any way possible?

Thanks again!
HD (now Dr. HD, in part thanks to DT and helpful people like you :mrgreen: )

Perfect. :wink:

AFAIK, DEVONthink doesn’t support command-click-drag for non-contiguous text in a PDF window.

With the QH&A script this is possible, selecting one passage at time and running the script after selecting each passage. The script is written so that it creates an annotation RTF file only the first time it is used on a PDF, and in subsequent select-and-run-script actions it will append to the same file - leaving you with a single editable document.

Indeed! Congratulations. 8)

YES!! It works perfectly. This is fabulous–many thanks to you and the person who created the script!!!

And thanks for the congratulations.
HD