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

In contrast to @mbbntu and perhaps others, I use sub-folders routinely. I prefer them. But, as I note here, my use-case may be unique. When I would have one theme underlying my reference collections, I might worry less about storing files in a single folder at the Finder level. I must say however that I have far greater appreciation for multiple sub-folders after working from Mendeley and Papers3, where references are stored in sub-folders by year. I also have much greater appreciation for sub-folders as I switch back and forth with various local libraries using Bookends on my iPad. I have by specific example no need to be seeing the hoards of references that are otherwise stored in a library called My Citations with attachments stored in a sub-folder with the same name. Far easier to archive this sub-folder and know it is safe as well.

FWIW, at some point soon after Jon releases the next update to Bookends, I will update the AppleScript that copies attachments to the default attachments folder for the library. I am waiting on a new feature that will improve the consistency in renaming a copied attachment via AppleScript versus when renaming is invoked internally by a user.


JJW

2 Likes

I also use folder structures; but very lightly.
I have just 3 subfolders corresponding to my 3 BE libraries.

1: @article library maps to @article subfolder.
2: @Books library mapped to @Books subfolder. This library and its corresponding subfolder contains books & dissertations
3: @Mics library mapped to @Misc subfolder–contains works that are not published yet: including class room handouts, presentations etc. I am thinking to move this library to Zotero because Zotero is much more efficient to collect informal material (blog posts, random articles ect ) from the Internet. But, for the moment, I am using BE to manage it.

My reasoning for separating books and dissertations from articles has been explained here. Basically, I want to split the large pdf files into smaller chunks so that the searching tools such as Foxtrot can faily and easily compare the articles against the larger works such as books.

The easiest approach is to dedicate a single subfolder for each BE’s library, because BE allows assignment of individual subfolders for each libraries. But, if one wants Finder subfolders within one Bookends library, she needs other tools, like @DrJJWMac has—might be cumbersome to maintain it in the long run.

@MichiganUser: if you are indexing the filed, you don’t need to worry about DT at all. It can just index them. It is a layer on top of your structure. You need to worry about folder structure iff you are importing the files to DT. You make BE manage the folders, and index those folders to DT.

1 Like

To be clear, I use one folder per library. I do not go deeper. I have about a half dozen libraries with the respective sub-folders in the main Bookends Attachments folder.


JJW

2 Likes

Thanks so much for this. Can I ask about the script – am I right that it’s like a “maintenance” script that will find PDFs already on your computer that you’ve failed to filed in Bookends, and then gathers them there? I think that I’m reading that right.

With apologies for the (yet further!) followup, you said something here that makes me think there might be some feature i’m missing. When you say “you make BE manage the folders,” you don’t mean that BE itself can manage the Finder folders, right? But rather that BE manages its own ~proprietary folder/group structure within each BE library?

I’m asking because this made me wonder if there some more obvious way to keep a Finder subfolder structure than I’d realized–i may very possibly just be missing something completely!

Like others here, I rarely use subfolders.Tags work in DT3 pretty much like folders, only better (and even this I don’t use all that often).

That’s easy enough: the DT3 record and the BE reference both point to the same file, so there there is a common element in both to be used as the starting point for the search. There are many ways to do this depending on what exactly you are trying to accomplish – e.g. just hitting a shortcut and going from one to the other? Having them share the ref metadata? Notes?

There are several scripts here in the forum and elsewhere that will allow you to do that and more. Feel free to DM if you need help with that.

3 Likes

That’s exactly it: just hitting a shortcut and going from one to the other. I just want to lock down my source trail between notes (DevonThink) and bibliography-ready source (Bookends), so that when I can immediately (1) figure out which PDF source was the origin for my text notes on a DT notecard, and (2) get the bibliographic information for that original PDF source

I often put a formatted citation in my notes, so that I can just copy it from there if I need it quickly (in Bookends, Command-K) and it is easy enough to copy the link for the item in Bookends (Shift-Option-Command-L). I then switch to my note and paste it in the text. Looks like this in a markdown note:

3 Likes

The script is only of value when you are using sub-folders to store attachments. The script copies PDFs into the default attachment folder for the library. It prefixes the file name with the name of the library. For example, suppose that you have a library MyCitations with a default attachments folder My Citations Folder. After running the script, all of the PDFs for the references in the library are in the folder My Citations Folder and are prefixed with MyCitations_. Suppose that you create a new library NewCitations with a default attachments folder New Citations Folder. You copy a citation XYZ with its attachment from MyCitations into NewCitations. Bookends will keep track of the attachment in My Citations Folder. But, I want a copy in New Citations Folder instead. I run the script. I will have two copies of the PDF

…/Attachments/My Citations Folder/MyCitations_2020 XYZ
…/Attachments/New Citations Folder/NewCitations_2020 XYZ

I prefer having duplicate files in locations at the Finder level that are defined by the library instead of having PDFs all (collected/scattered about) in the Attachments folder.

Hope this explains the intent.


JJW

2 Likes

I am thinking about the “default attachment subfolder” feature of BE–it lets you assign a subfolder for each library.

You can also move pdf files to default subfolders of the library using using BE’s “consolidate ad hoc attachments” feature.

Thus far I can tell, these are the two features BE offers for managing subfolders for the files.

1 Like

For the linking of the records across the two applications, you need to check out the script here: Autolinking Bookends and DEVONthink records - Sonny Software

and
Bookends Devonthink Highlights app workflow - Sonny Software

3 Likes

This script might be useful too for users who simply index the complete attachments folder of Bookends as it doesn’t index attachments on its own, instead it matches already indexed files inside all opened databases to all attachments of the frontmost library window of Bookends.

The URL of the indexed attachments links to the record in Bookends and optionally User20 field in Bookends links back to DEVONthink.

-- Cross-links indexed files in DEVONthink's databases and attachments of Bookends

-- Optionally sets User20 field of Bookends' reference to DEVONthink's item link
-- In case of multiple attachments or an attachment indexed multiple times the item link is not unique and therefore the field not changed
property pUser20ItemLink : false

-- Optionally set Finder comment to formatted reference using the specified format
-- Use e.g. "RIS.fmt" instead
property pCommentFormat : ""

-- Optionally set aliases to citekey
property pCitekeyAliases : false

tell application "Bookends"
	tell front library window
		repeat with theItem in publication items of group attachments
			set itemLink to ""
			set numCrossLinks to 0
			set {theID, theAliases} to {id, citekey} of theItem
			set theURL to ("bookends://sonnysoftware.com/" & theID) as string
			
			if pCommentFormat is not "" then
				set theComment to format theItem using pCommentFormat
			else
				set theComment to ""
			end if
			
			repeat with theAttachment in attachment items of theItem
				set thePath to path of theAttachment
				
				tell application id "DNtp"
					repeat with theDatabase in databases
						repeat with theRecord in lookup records with path thePath in theDatabase
							set recordURL to URL of theRecord
							if recordURL is "" or recordURL is equal to theURL then
								set URL of theRecord to theURL
								if pCitekeyAliases then set aliases of theRecord to theAliases
								if theComment is not "" then set comment of theRecord to theComment
								set itemLink to reference URL of theRecord
								set numCrossLinks to numCrossLinks + 1
							end if
						end repeat
					end repeat
				end tell
			end repeat
			
			if pUser20ItemLink then
				if numCrossLinks > 1 then
					set theTitle to title of theItem
					tell application id "DNtp" to log message theTitle info "Record has multiple indexed attachments."
				else if numCrossLinks is 1 and user20 of theItem is "" then
					set user20 of theItem to itemLink
				end if
			end if
		end repeat
	end tell
end tell
1 Like

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

I’d like to suggest that you

  • move the error handing to the top (ie checking for number of selected records, checking for attachment)
  • simplify it some: if count of selected records not equal 1 error... (in pseudo code)
  • get rid of the if attachment not equal "" check: the script already bailed out if there is no attachment, no need to check again.

These are just a matter of taste of course, but I think that they make the code easier to read and understand.

1 Like

Sorry for such a slow reply – stuff went a little crazy for me in the early summer, and I forgot entirely that I’d been trying to figure this out.

And thank you!! That script looks amazing–precisely perfect for me, since my PDFs are indeed already indexed by Devonthink. I’m going to try to figure out how to run it now and crossing my fingers I can get it going–it seems perfect

1 Like

Sorry that I have been slow to reply (due to work-related reasons), as this is an interesting discussion. About new PDFs/files in general.

  1. For new PDFs, I either download the PDF myself or start from an Alfred Workflow designed to search online for the PDF → start the download → place the downloaded file in a Bookends watched folder.
  2. I eventually check the new Bookends reference, and after it’s filled, I sync the data to DT3. That is, I use and script to…
    • bring the content of all the fields over as metadata from BE to DT3,
    • the RIS ref to the comment field of the PDF,
    • the content of the DT3 Annotations back to the Bookends Notes field,
    • other DT3 data back to BE, such as URL/UUID, tags, etc.

I am still working out the best solution for merging DT3 tags and Bookends keywords. I still haven’t found an optimal solution that will use the best of both worlds and allow me to edit it somewhere and sync it elsewhere, keeping the latest changes regardless of where they occurred.

Learning how to use DEVONthink, Bookends, Scrivener, and Tinderbox all in tandem, and working side-by-side, did take time and effort, I won’t deny, but I want to think that it was a good investment in the future, not unlike completing my academic degree. Once I finish my Ph.D. early in 2023, I will try to take some time to document how all of this work in greater detail and share the workflows. The only issue is that documenting is another work in itself, and I may have to start looking for work right away.

4 Likes

this is awesome–thank you so much!!!

Dear Bernardo

I sincerely hope you were able to finish your PhD (I know how that feels …). If so, I would be really interested in any further information on your workflow, especially the DNT ↔ Bookends part. Thx.

1 Like