Tip: How to index individual BibDesk entries in DEVONthink

BibDesk is a great open-source reference management software package for Mac OS X. You can use it to manage bibliographies and scholarly references when writing essays and articles.

BibDesk stores bibliographic entries in a BibTeX database file. (For example, I have over 20,000 carefully curated bibliographic entries in one BibTeX database file.) BUT if you index this BibTeX database file in DEVONthink, DEVONthink will not show a list of related individual BibDesk bibliographic entries in the see-also list (in the See Also & Classify drawer) when you are viewing another file in DEVONthink.

This post describes a workaround for indexing individual BibDesk entries in DEVONthink so that they appear as individual items in the see-also list. It is the best method I have found to get individual BibDesk bibliographic entries listed in DEVONthink’s see-also list. (If anyone has a better method that I have overlooked, please share it in a response.) Here is the method:

  1. First, you need to understand that each time you use BibDesk to save a BibTeX database file, BibDesk saves a metadata file (with extension .bdskcache) for each individual bibliographic entry into a subfolder of your ~/Library (User Library) folder. These metadata files are then indexed by Spotlight so that whenever you do a search using Spotlight, relevant bibliographic entries are listed in the search results. But if you try to index this folder in DEVONthink, the content of each .bdskcache file does not appear to be indexed completely. So first you have to tell DEVONthink to index .bdskcache files as text files by setting one of DEVONthink’s hidden preferences. If DEVONthink is running, make sure that you quit it. Then open Terminal.app and run the following command:

defaults write com.devon-technologies.thinkpro2 AdditionalPlainTextExtensions -string .bdskcache

(Note that users of DEVONthink Personal should replace the text “thinkpro2” in the code above with “think2”, and if you have other extensions that you want to be interpreted as plain text, you should append them to the string, for example: .bdskcache.otl.todotxt). Then open DEVONthink and it will read the new preferences.

  1. Second, you need to tell DEVONthink to index the folder of BibDesk metadata files. You can do this in the usual way you index folders: either by selecting File > Index… or by navigating to the folder in Finder and then holding down the option and command keys and dragging the folder into your DEVONthink database. Either way, you can go to the folder directly by typing shift-command-G and pasting ~/Library/Caches/Metadata/edu.ucsd.cs.mmccrack.bibdesk into the window. If your collection of bibliographic entries is large, it may take some time to index.

  2. Third, now when you select any file in DEVONthink and click on the See Also & Classify button or menu item, any related bibliographic entries will appear in the see-also list. The name of each entry will be the entry’s BibTeX citation key. If you click on a bibliographic entry in the see-also list and press the space key on your keyboard, a nicely formatted Spotlight preview will show basic bibliographic data. If you click on a bibliographic entry in the see-also list and press shift-command-O (or press the toolbar button Open in external editor or viewer) BibDesk will open and the entry will be selected in a BibDesk window.

This method works especially well for annotated bibliographic entries: Enter any relevant information about a reference in the entry’s Abstract field in BibDesk, and that information will now be saved and indexed in DEVONthink and will be cross-referenced in relevant see-also lists.

2 Likes

Thanks for the thorough step-by-step. I’m sure we have some BibDesk users that will find this helpful. :smiley:

I have just started experimenting with Bibdesk and this is a very neat solution very clearly explained.

Thank you Nat.

Frederiko

There is an important related issue: BibDesk’s equivalent of tags are keywords. It would be nice to have DEVONthink read the keywords of BibDesk entries and convert the keywords to tags.

In fact, this conversion of BibDesk keywords to tags is easily done using a script in DEVONthink Pro: First you need to go to the Scripts menu in DEVONthink Pro, select More Scripts…, and install the script titled Convert Keywords to Tags. Then select all the indexed .bdskcache files in DEVONthink Pro and run the script from the menu item Scripts > Tags > Convert Keywords to Tags. But there is a catch: This script ONLY works when you have not told DEVONthink Pro to index .bdskcache files as text files (as instructed above).

So if you want your BibDesk keywords to appear as tags in DEVONthink, AND you want BibDesk entries to appear in DEVONthink’s see-also list, the procedure for indexing BibDesk entries that I described above requires a few more steps (in DEVONthink Pro):

  1. First, you need to make sure that DEVONthink Pro is NOT indexing .bdskcache files as text files. If you already created the hidden preference as described above, you can delete it by running the following command in Terminal.app (after quitting DEVONthink Pro): ```

defaults delete com.devon-technologies.thinkpro2 AdditionalPlainTextExtensions


2. Second, index the folder [i]~/Library/Caches/Metadata/edu.ucsd.cs.mmccrack.bibdesk[/i] in DEVONthink Pro.

3. Third, select all the indexed .bdskcache files in DEVONthink Pro and run [i]Scripts > Tags > Convert Keywords to Tags[/i]. When the conversion is finished, all your BibDesk keywords will show as tags in DEVONthink Pro.

4. Fourth, delete the indexed folder [i]~/Library/Caches/Metadata/edu.ucsd.cs.mmccrack.bibdesk[/i] in DEVONthink Pro (not the external folder) and empty the trash. Then quit DEVONthink Pro and follow all the steps described in the original post of this thread.

Alternatively, it would be possible to write a script or Automator action to convert keywords (kMDItemKeywords) to tags (kMDItemUserTags) outside of DEVONthink Pro, thus making the process available to users of DEVONthink Personal. An external script or Automator action would be much better because it would not be necessary to go through all the extra steps in this post; you would just need to run the external script or Automator action before updating the indexed .bdskcache files in DEVONthink.

I wrote the following AppleScript to make it easier to turn on and off the setting for reading BibDesk cache files as plain text.

I saved the AppleScript in ~/Scripts/DEVONthink Pro (not in ~/Scripts/Applications/DEVONthink Pro). Whenever I feel the need to re-convert the keywords of BibDesk entries to tags (because I’ve changed many keywords in BibDesk or added many new entries), I trash the indexed folder of BibDesk cache files in DEVONthink Pro and empty the trash, then quit, then run my script (see below) from the system script menu, then reopen DEVONthink Pro, reindex the folder of BibDesk cache files, and run the script Scripts > Tags > Convert keywords to tags in DEVONthink Pro. Then I trash the indexed folder of BibDesk cache files in DEVONthink Pro and empty the trash, then quit, then run my script again, then reopen DEVONthink Pro and reindex the folder of BibDesk cache files (as plain text). It’s more maintenance than I would like to do, but it seems this is what needs to be done to make sure that BibDesk entries are available in DEVONthink’s see-also list AND that they are properly tagged in DEVONthink.

This AppleScript assumes that the only additional extension to read as plain text is “.bdskcache”; if there are other extensions you want to read as plain text, you should append them to “.bdskcache”, for example: “.bdskcache.otl.todotxt”.

set defaults_written to false
try
	set defaults_read to (do shell script "defaults read com.devon-technologies.thinkpro2 AdditionalPlainTextExtensions")
on error
	set defaults_written to true
	do shell script "defaults write com.devon-technologies.thinkpro2 AdditionalPlainTextExtensions -string '.bdskcache'"
	display dialog "DEVONthink Pro will now index BibDesk cache files as plain text files." buttons {"OK"} default button "OK"
end try
if defaults_written is false then
	do shell script "defaults delete com.devon-technologies.thinkpro2 AdditionalPlainTextExtensions"
	display dialog "DEVONthink Pro will now index BibDesk cache files normally, not as plain text." buttons {"OK"} default button "OK"
end if

I wrote a script to convert BibDesk keywords (kMDItemKeywords) to tags (kMDItemUserTags) outside of DEVONthink Pro, thus making it much easier to have tagged and indexed BibDesk entries in DEVONthink because it is no longer necessary to go through all the extra steps in my second post above.

It is a bash script, so it requires some familiarity with the Terminal. Save the following code as a script and make it executable (for example, with the command chmod +x scriptname). Then run the script prior to updating the indexed .bdskcache files in DEVONthink.


#!/opt/local/bin/bash
# Description: Iterates over the folder of BibDesk cache files, copying each file's keywords metadata (kMDItemKeywords) to its tags metadata (kMDItemUserTags) on files with keywords, and erasing tags on files without keywords.
# Requirements: Two programs, "tag" and the latest GNU "bash" (v4.4+), must be installed; the latter is required for 'printf %b' command to properly convert universal character names to Unicode (which only seems to work in an interactive shell, so always run it from Terminal and not in a noninteractive shell, although if there are no non-ASCII characters in your keywords it won't matter). This script uses the MacPorts path locations, so if your programs are installed elsewhere then change "/opt/local/bin/" to your path.

IFS=$'\n'
nullkeywords="kMDItemKeywords = (null)"
cd ~/Library/Caches/Metadata/edu.ucsd.cs.mmccrack.bibdesk/
for file in *.bdskcache; do
  keywords=$(mdls -name kMDItemKeywords "$file")
  if [ "$keywords" == "$nullkeywords" ]; then
    /opt/local/bin/tag -s '' "$file"
  else
    keywords=$(mdls -name kMDItemKeywords "$file" | sed -e '/kMDItemKeywords = (/ d' -e 's/\([^\\]\)"/\1/g' -e 's/^   *//' -e 's/\\"/"/g' -e '/)/ d' | tr -d '\n')
    /opt/local/bin/tag -s $(printf %b "$keywords") "$file"
  fi
done
osascript -l AppleScript -e "beep"
echo "Finished converting BibDesk keywords to tags."

Any questions about or feedback on the script are welcome. I will probably create another version that runs only on files that have been modified since the last time I updated the indexed .bdskcache files in DEVONthink, so as to reduce the time that the script takes to run.