Find matching PDF using AppleScript

I would like to invoke a script to find DevonThink items that match a PDF attached to a record in Bookends. The script would be invoked from Bookends with a single selected record.

I’ve been playing around with compare in DT’s AppleScript dictionary to find DT items that contain the author name and title. However, this can bring up multiple hits (e.g., other PDFs that cite the PDF-of-interest).

I am thinking the more rigorous way would be to extract a chunk of text from the PDF-of-interest and compare items in Devonthink.

Is there a better way to approach the problem? Is there a script that already does this?

No, there is no script that does this (which is a very specific operation).

Have you considered indexing Bookend’s attachments then using DEVONthink’s See Also & Classify inspector?

It’s a long and complicated story… I’m so deeply invested at this point in imported versions of my PDFs that I couldn’t imagine switching to indexing.

Too far down the rabbit hole, I’m afraid. For example, I have a lot of writing outside DT that points to imported PDFs using DT’s fabulous UUIDs (thank you for this feature!). This gets me to the PDF I want very reliably regardless of what app I’m writing in and on what device (laptop, desktop, iPad, iPhone). Redefining all those external links to point to new UUIDs associated with indexed versions of my PDFs would be a nightmare.

Going forward, I think I have a good working solution. For new PDFs that I find when doing literature search, I have a workflow and AppleScript to link Bookends record to DT items. Step 1) I import PDF into Bookends, which then autofills metadata for the PDF (author, title, year, journal, etc). Step 2) An AppleScript triggered from Bookends pushes the PDF to DT, fills its metadata appropriately (including a backlink to Bookends) and updates the Bookends record with the DT-generated UUID. This seems to work very well for new PDFs that I’m adding to Bookends/DT. (Thanks to tips from here).

The challenge is to patch up the link between Bookends and DT for the 4000+ older PDFs that I have in my system. :slight_smile: Thus, my query to see if I can prompt an AppleScript to find a PDF in DT that matches an attachment in Bookends. If I can make the match reliably, the rest is easy. I think I’m close with compare in AppleScript. The PDF I want is found, but usually a few other PDFs also show up. I could probably use other search terms to whittle down the search. It won’t be perfect, but it will be pretty darn good. I’ll post my code when I have something decent.

I’m not trying to talk you into any course of action, but broken UUIDs is not a problem. If you move imported documents to an indexed group in DEVONthink, the document will be exported to the indexed folder in the Finder and the document will maintain its unique UUID in the database.