Bookend and Obsidian Users,
I use Bookends, Obsidian, and Devonthink as the core of my research and annotation process. I have a script in the Bookends folder that allows me to export all of my Bookends notes/annotations to a single Markdown file that is imported to Obsidian. I have a second script that exports the same notes to Devonthink as an opml file that separates each note into a different text file that I then convert, in Devonthink, to Markdown format. Both scripts are adaptations of scripts that other, better programmers, built to work with Bookends. Below I’ll share the script that exports a single Markdown file for import to Obsidian. Before I do, however, I need to explain how I format my notes in Bookends, because the formatting matters a lot for the script
Each Bookends note or annotation is formated as follows:
Line 1: #@<pg> <ID> <Note Title>
Line 2: <Note Content>
or for notes that include a quotation:
Line 1: #@<pg> <ID> <Note Title>
Line 2: > <quotation>
Line 3: <comments on quotation>
So, for example, here are two notes from Susan Wells’ book, Sweet Reason
#@3 210614-1104 Modernity as a system of texts - quotation
> Modernity is a system of texts that we are only now learning to read.
Susan Wells argues here that modernity is more than just a period of time. It is a mode of writing, a system that articulates certain relationships and those relationships are, for the most part, distinctions that separate reason from desire or academic writing from governmental writing. Modernity as writing is all about seemingly “natural” classifications that are designed according to the character of what is being written or the context in which it takes place.
#@4_6 210614-1108 Modern Rhetoric as a set of compositional themes
Wells seems to indicate on pages 4 through 6 that the text of modernity is a rhetoric that attends to the materiality of writing, to its entrainment in relations of desire and displacement, as it will attend to various narratives of power, knowledge, disclosure, and conversion.
The script I’m about to paste below presumes that each Bookends note is structured fairly closely to what you see above. OK. here is the Bookends Script that I run to produce a single Markdown Annotation File of a Bookend’s source.
-- Script to create Annotations summary from Bookends reference
-- Original Script by Kyle Eggleton, November 2019
-- Adaptations to Script by Kirt Wilson, February 2021
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 theCitation to citekey of theRef -- user1 is the Bookends field where BibTex citation is stored
set theAbstract to abstract of theRef
set theAuthors to author names of theRef
set theAuthorDate to format theRef using "Author Date.fmt"
set theTitle to title of theRef
set theShortTitle to short title of theRef
set theJournal to journal of theRef
set thePubdate to publication date string of theRef
set theDOI to doi of theRef
set theKeywords to keyword names of theRef
set theProjects to user4 of theRef
set theFormattedReference to format theRef using "APA 6th Edition Markdown.fmt" --change to reflect the formatted reference required
set theNotes to the notes of theRef
end tell
end tell
--Format the annotations summary to Markdown
set theNotes to replaceText("#", "### ", theNotes)
set theNotes to replaceText("@", "Page ", theNotes)
set theReference to replaceText("
", "", theFormattedReference)
set theAnnotations to "---
aliases: [" & theShortTitle & "]
ID: <% tp.file.creation_date(\"YYMMDD-HHmm\") %>
type: annotation
author: [\"" & theAuthors & "\"]
pubdate: " & thePubdate & "
doi: " & theDOI & "
bkurl: bookends://sonnysoftware.com/" & theID & "
created: <% tp.file.creation_date(\"MMMM DD, YYYY\") %>
tags:
---
# Annotations: " & theAuthorDate & "
**Title**:: " & theTitle & "
**Authors**:: " & theAuthors & "
**Citation**:: [" & theCitation & "](bookends://sonnysoftware.com/" & theID & ")
**Reference**:: " & theFormattedReference & "
**BookendURL**:: bookends://sonnysoftware.com/" & theID & ")
**Project**:: [[" & theProjects & "]]
**Abstract**:: " & theAbstract & "
---
## Annotations
" & theNotes & "
ID: <% tp.file.creation_date(\"YYMMDD-HHmm\") %>"
-- Save notes as a markdown file
set refPath to POSIX path of (choose file name with prompt "Save As File" default name "Notes.md" default location path to desktop) as text
if refPath does not end with ".md" then set refPath to refPath & ".md"
do shell script "echo " & quoted form of theAnnotations & "> '" & refPath & "'"
--Replace text subroutine
on replaceText(searchString, replaceString, theText)
set AppleScript's text item delimiters to searchString
set theItems to every text item of theText
set AppleScript's text item delimiters to the replaceString
set theText to the theItems as string
return theText
end replaceText
So, if the script runs successfully, you end up with a single Markdown file that has a YAML header, a Title, a section that provides citation information, and a series of notes all separated by ‘###’.
In my own workflow, I go one step further by running a regexp search/replace on the file using BBEdit. This search/replace pattern places the page number and ID at the end of each note rather than allowing it to appear in each note’s title. I like this formating better. That regular expresses is as follows:
Find: ^(### )(Page\s([0-9,_]{1,7}))\s([0-9](.\d\d\d\d-\d\d\d\d))(.*)\n(.*)
Replace: \1\6\n\7 (\2) ^\4
That’s it. I hope that this is useful to someone else who is using Bookends and needs to generate a Markdown file of their Bookend Annotation Notes. Obviously, this file is useful for Obsidian, but it could work in any note app that accepts Markdown formatting.
Best,
Kirt Wilson