Page 1 of 1

Help With a Script

Posted: Tue Sep 01, 2020 10:13 am
by doclrb
From time to time, I have attempted to integrate the attached script for DevonThink in my Bookends workflow. The script was kindly provided by a power user, Kyle Eggleton.

The script imports the title, authors, etc, but doesn't import the items of particular interest. That is, the annotations on the notecards. Would anybody kindly pls write the line(s) of text that would accomplish that last detail?

-- Script to create Annotations summary from Bookends reference linked to indexed DEVONthink file
-- Kyle Eggleton June 2019

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 user1 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 theJournal to journal 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
set theLink to user4 of theRef


--Error message if no DEVONthink link exists
if theLink is {} then error "No DEVONthink link made in Bookends"


end tell
end tell

--Format the annotations summary to Markdown
set theUUID to replaceText("x-devonthink-item://", "", theLink)
set theNotes to replaceText("#", "####", theNotes)
set theNotes to replaceText("@", "Page ", theNotes)
set theReference to replaceText("
", "", theFormattedReference)

set theAnnotations to "# Annotations: " & theAuthorDate & "

**Title:** " & theTitle & "

**Authors:** " & theAuthors & "

**Citation:** [" & theCitation & "](bookends://sonnysoftware.com/" & theID & ")

**Reference:** " & theFormattedReference & "

**Abstract:** " & theAbstract & "

##Annotations



" & theNotes

-- Create Annotations file in DevonThink
tell application "DEVONthink 3"
set theRecord to get record with uuid theUUID
set theGroup to create location "/Annotations/EMS" in the current database
set theMDRecord to create record with {name:theAuthorDate & " (Annotations)", type:txt, URL:theLink, content:theAnnotations} in theGroup
set name of theMDRecord to theAuthorDate & " (Annotations).md"
set theMDLink to the reference URL of theMDRecord
add custom meta data theMDLink for "annotationlink" to theRecord -- change the field name to suit own purposes/custom meta data field

end tell

--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

Many Thanks

doclrb

Re: Help With a Script

Posted: Tue Sep 01, 2020 11:04 am
by Jon
Please move this post to the AppleScript forum.

Jon
Sonny Software