Autolinking Bookends and DEVONthink records

Users asking other users for AppleScripts that work with Bookends.
Post Reply
Posts: 9
Joined: Sun Aug 27, 2017 12:47 am

Autolinking Bookends and DEVONthink records

Post by zvh » Fri Feb 08, 2019 6:32 pm

Hi all,

I thought I might contribute another script that I recently completed and that seems to work like a charm.

I've read some users of both Bookends and DEVONthink wish (on both forums) that you could automatically link records between the two softwares. The script located on the gist I've just posted, provided your files correspond to a certain naming convention, should allow you to do this. I've just run it on my own Bookends library of over 3500 records and can't find a single instance of a bad or incorrect link.

By link I mean that I automatically place the Bookends URL in the URL field of the record in DEVONthink and then the DEVONthink item link in the user20 field of the Bookends record. Not only that but I place the RIS data from Bookends into the comment field of DEVONthink and make the BibKey its alias. This means that, should you turn on Wikilinks in DEVONthink, you'll be able to use the BibKey as a link, whether to the original document or, for my purposes, to notes for the document. Both the RIS and BibKey records also serve as forms of redundancy that would allow you to get all the cite information (and essentially reconstitute your entire digital library with records) if need be.

Finally, the script passes any pdf through exiftool on the command line to place the author (or editor), title, and BibKey (as subject) records into the pdf itself.

Now, what the script does is loops through an entire Bookends SQL Smart Group, which I've set up using the following parameters:

Code: Select all

(attachments IS NOT NULL) AND (user20 IS NULL) AND (thedate IS NOT NULL) AND (attachments REGEX '^\S*\d{4}[a-z]?-\S*?(?=\.).(pdf|epub|mobi|md)')
So, what this says is that the record to be processed has to have attachments (or else there's nothing to link to), it can't already be linked (you don't want to do this to the same file multiple times but do want to know which ones you haven't yet processed, so user20 has to be empty), and also has to have a date (as the BibKey is the unique thing about my file naming system that guarantees a match when searching in DEVONthink). It also has to have an attachment that corresponds to the given RegEx, because I don't want to have to rename the pdf later and threaten breaking the links (although then I'd just reprocess, which would replenish all the lost metadata).

I've named this group "Unlinked Attachments," and you'd need to change this, as well as the location of your DEVONthink library location, if you decided to use a version of the script. Also, and this is essential: ensure your naming system produces unique names. Otherwise I don't think this script would be quite as effective and may produce false matches in the search function.

Caution: As this script does things to your files, please a) don't use it if you don't know enough AppleScript to know what the script is doing in order to be able to alter it to your own specifications; b) perform a backup of your Bookends library, your digital files, and your DEVONthink database prior to using the script; and c) consider using the second gist linked to below to start, which will just try this on a single file that you've selected in Bookends. This should allow you to test it with your own file, naming, and database structures. Your DEVONthink database does need to be open but you don't have to select anything inside of it.

As I said, this cycled through 3500 references, and even seems to have achieved a correct match in cases where file names were nearly identical or multiple files were attached to a single Bookends record. Again, this script will have different applications for anyone who chooses to use it. It's so individual to each user that I can't offer to customize it for anyone. I just wanted to show how something like this might be done.

All best,


Link all records in group: ... 1c0a3dc241

Link selected record: ... 01622fbf12

Post Reply