Help-New txt file with selected text in external PDF reader

I’m looking for some scripting help. I am using a script by user KORM that copies selected text to a RTF and sets the url to the source file. The script is fantastic because it automatically populates the file name (with the source file name) and asks me for a location to save within DEVONthink.

Here is a link to the thread where I found the original script.

I modified the script to append a number (representing number of seconds since midnight) to the file name to ensure that new text files have a unique identifier when generated from the same PDF. I also changed the file type to plain text.

This script works great for copying “chunks” of text from my PDFs… but the DEVONthink PDF viewer struggles due to unresolved problems with PDFKit. I frequently have rendering errors that make the PDF unreadable (blocks of text missing or corrupted— blurry rendering— or slow to render at all – macOS 10.12.4 – DTPO 2.9.11).

I am hoping to recreate this workflow using an external program such as PDF Expert. Basically, I would like to open up PDFs that are indexed (DEVONthink) in PDF Expert and create a new plain text file (in DEVONthink) with selected text that includes a reference to the source in the url property of the text file.

Thanks for the help DEVON community!

PDFExpert is not scriptable. The developer did not provide a scripting dictionary to expose documents or other features of the program to AppleScript. Nor does it have a URL scheme, so there is no way to link to text and cause PDFExpert to open. You could probably kludge together something using GUI scripting + KeyboardMaestro, but that sort of thing is fragile, ugly, and thankless. :open_mouth:

Consider using Highlights, which does this sort of thing well (slightly differently than you described, though), and integrates OK with DEVONthink.

Thanks for the reply and explanation KORM. I did try Highlights (interestingly PDF Expert can also export a plain text file of annotations) but this still requires splitting the exported text file up into multiple files and copying the devonthink URL. I was hoping to streamline this process a bit. I have found smaller text files work better with the AI — and this strategy has proved useful for abstracting/linking important pieces of information from journal articles.

Do you think this may be possible with different PDF app? Not sure if Preview or PDFPen fit the bill?! Basically, I just want to keep the process intact but use a PDF viewer that doesn’t fall down because of the problems in PDFKit.

Thanks again,


Preview is scriptable, but barely. PDF Export Pro is your best bet – it’s very scriptable. A lot of work for not much, so I’ll take pass on writing that one.

But the existing script is working perfectly well in DEVONthink so I don’t see why change is needed. All it doing is selecting text in a window, and that has nothing to do with Sierra’s PDF issues. As long as the document is PDF+Text, the text is selectable. If you are having problems selecting text, it is because the OCR was botched, not because you’re using Sierra.

Thanks for the help Korm. The script does work well in DEVONthink.