Bookends and DevonThink "side by side" with same PDF folder -- risky?

I use a modified version of the script posted here:


-- Script to link DEVONthink file and Bookends reference along with custom metadata
-- Kyle Eggleton April 2019, modified December 2021 (guylaine)

tell application "Bookends"
	tell front library window
		
		-- Get selected publication 
		
		set theRefs to selected publication items
		set theRefsNo to count of theRefs
		set theRef to first item of theRefs
		
		-- Error messages	
		
		if theRefsNo is greater than 1 then error "Select only one item"
		if theRefs is {} then error "Nothing selected in Bookends"
		
		-- Get properties of selected reference
		
		set theID to id of theRef
		set theDOI to doi of theRef
		set theAbstract to abstract of theRef
		set theAuthor to authors of theRef
		set theTitle to title of theRef
		set thePubDate to publication date string of theRef
		set theISBN to isbn of theRef
		set theRating to rating of theRef
		set theKeywords to keyword names of theRef
		set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}
		set theKeywords to theKeywords as text
		set AppleScript's text item delimiters to TID
		set theAttachments to attachments of theRef
		set theJournal to journal of theRef
		set theFormattedReference to format theRef using "Vancouver.fmt" --Change to theformat in Bookends that you want
		
		-- Only set metadata fields for PDF if there is an attachment
		
		if theAttachments is equal to "" then error "There is no file attached to the Bookends reference"
		if theAttachments is not equal to "" then
			set theFile to the first attachment item of theRef
			set thePath to the path of theFile
			if theFile is "" then error "The file is missing from the Bookends reference"
			
			-- Set the metadata fields for PDF. Need to install exiftool (https://www.sno.phy.queensu.ca/~phil/exiftool/install.html)
			
		end if
	end tell
end tell


-- Set URL to Bookends and custom metadata in DevonThink. Need to create custom meta data fields for Abstract, Citation, Reference, Published and Bookends URL

tell application id "DNtp"
	set theURL to ("bookends://sonnysoftware.com/" & theID) as text
	set theRecord to the content record of think window 1
	if theRecord is {} then error "Nothing selected in DEVONThink Pro"
	set rating of theRecord to theRating as integer
	add custom meta data theURL for "beurl" to theRecord
	add custom meta data theAbstract for "abstract" to theRecord
	add custom meta data thePubDate for "published" to theRecord
	add custom meta data theISBN for "is?n" to theRecord
	add custom meta data theDOI for "doi" to theRecord
	add custom meta data theFormattedReference for "reference" to theRecord
	set theLink to reference URL of theRecord
	
	do shell script "/usr/local/bin/exiftool -title=" & quoted form of theTitle & " -author=" & quoted form of theAuthor & " -sep \", \" -keywords='" & theKeywords & "' -subject=" & quoted form of theJournal & " -overwrite_original " & quoted form of thePath
	
end tell

-- Set URL to DEVONThink in Bookends (using user4 field)

tell application "Bookends"
	tell front library window
		set user4 of publication item id theID to (theLink & "?reveal=1")
	end tell
	
end tell

It does much more than just link (copies basically all the info from Bookends to DT so you can have more than the file name in DT), but only processes one file at a time, which needs to be selected in both Bookends and DT when you run it. If all you want is linking, the script posted by @cgrunenberg is the way to go.

2 Likes