Import selected Bookends references (& save note URL back to the reference)

There is an Applescript in the code container and a stamp to run it.

Hope this is useful.

Bookends.tbx (179.5 KB)

3 Likes

Bernardo, many thanks for this - it looks very interesting!
However, compiling, saving and running it, it only imports one of my selected references from Bookends into Tinderbox; and it doesn’t put anything (except the author name) into the key attributes.
I attach a screenshot to give you an idea - this is the state after I made the new note of prototype “Reference”. There were five items selected in Bookends, but only one was imported.
Any idea what the problem is - or what steps I may have missed before calling the script?
Thanks for any help you can give!

Hi @abusch, have you tried using the stamp provided?

Update: I see that in your file you ran the script as a stamp and directly from the Tinderbox file (i.e. without going through the AppleScript Editor etc.).
When I did that, import into key attributes worked fine (see attached screenshot), but it still only worked for the first of five selected Bookends references…

It is probably running into an error. This also happened to me when I was importing a larger number of references into Tbx. I couldn’t single out the cause, but it was on Tbx’s side and not on Bookend’s, I think.

Here is the unescaped script, if you want to try and run it from the editor and see if anything is coming up.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "Bookends"
	tell front library window
		set theRefs to selected publication items
		set theRefsNo to count of theRefs
		repeat with theRef in theRefs
			set theType to type of theRef as text
			set theID to id of theRef
			set theAbstract to abstract of theRef
			set theAuthors to authors of theRef
			set theEditor to editors of theRef
			set theTitle to title of theRef
			set theAbstract to abstract of theRef
			set thePublisher to publisher of theRef
			set theLocation to location of theRef
			set theVolume to volume of theRef
			set theKeywords to keyword names of theRef
			set theKeywords2 to keywords of theRef
			set theDate2 to publication date string of theRef
			set theURL2 to url of theRef
			set theISBN to isbn of theRef
			set theDOI to doi of theRef
			set theTranslator to user3 of theRef
			set theBibkey to user1 of theRef
			set thePages to pages of theRef
			set theIssue to volume of theRef
			set theNotes to notes of theRef
			set theLanguage to language of theRef
			set theAttachments to attachments of theRef
			set theJournal to journal of theRef
			set theShortTitle to short title of theRef
			set theFormattedReference to format theRef using "ABNT.fmt"
			if theType is "1" then set theType to "Artwork"
			if theType is "2" then set theType to "Book"
			if theType is "3" then set theType to "Book Chapter"
			if theType is "4" then set theType to "Conference Proceedings"
			if theType is "5" then set theType to "Dissertation"
			if theType is "6" then set theType to "Edited Book"
			if theType is "7" then set theType to "Editorial"
			if theType is "8" then set theType to "In Press"
			if theType is "9" then set theType to "Journal Article"
			if theType is "10" then set theType to "Letter"
			if theType is "11" then set theType to "Map"
			if theType is "12" then set theType to "Newspaper Article"
			if theType is "13" then set theType to "Patent"
			if theType is "14" then set theType to "Personal communication"
			if theType is "15" then set theType to "Review"
			if theType is "16" then set theType to "Internet"
			if theType is "17" then set theType to "Ed. CrĂ­tica"
			if theType is "18" then set theType to "Trans Book"
			if theType is "19" then set theType to "Ed. CrĂ­tica"
			if theType is "20" then set theType to "Bekker"
			if theType is "21" then set theType to ""
			try
				set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ", "}
				set theTags to keyword names of theRef
				set theTags to (theTags as string)
			end try
			set theFormattedReference to format theRef using "ABNT.fmt"
			tell application "Tinderbox 8"
				tell front document
					if not (exists) then error "No Tinderbox document open."
					set newNote to make new note
					tell newNote
						set value of attribute "Prototype" to "Reference"
						-- set value of attribute "Name" to "@" & theCitation
						set value of attribute "Text" to theFormattedReference & linefeed & theAbstract & linefeed & theNotes
						set value of attribute "Authors" to theAuthors
						set value of attribute "Editor" to theEditor
						set value of attribute "Translator" to theTranslator
						set value of attribute "PublicationCity" to theLocation
						set value of attribute "Publisher" to thePublisher
						set value of attribute "PublicationYear" to theDate2
						set value of attribute "Journal" to theJournal
						set value of attribute "RefKeywords" to theTags
						set value of attribute "URL" to "bookends://sonnysoftware.com/" & theID
						set value of attribute "Abstract" to theAbstract
						set value of attribute "BibTexKey" to theBibkey
						set value of attribute "RefShortTitle" to theShortTitle
						set value of attribute "Type" to theType
						set value of attribute "Language" to theLanguage
						if theType is "Edited Book" then
							set value of attribute "BookTitle" to theTitle
						end if
						if theType is "Ed. CrĂ­tica" then
							set value of attribute "BookTitle" to theTitle
						end if
						if theType is "Trans Book" then
							set value of attribute "BookTitle" to theTitle
						end if
						if theType is "Book" then
							set value of attribute "BookTitle" to theTitle
						end if
						if theType is "Journal Article" then
							set value of attribute "ArticleTitle" to theTitle
						end if
						if theType is "Book Chapter" then
							set value of attribute "ArticleTitle" to theTitle
							set value of attribute "BookTitle" to theVolume
						end if
						if theType is "Bekker" then
							set value of attribute "ArticleTitle" to theTitle
							set value of attribute "BookTitle" to theVolume
						end if
						set NoteURL to value of attribute "NoteURL"
					end tell
				end tell
			end tell
			set user8 of publication item id theID to NoteURL
		end repeat
	end tell
end tell

Also, please note I am using certain user attributes that need to be created in a new tbx file before this could work properly.

I do not really know AppleScript, but looking at your code it seems that the number of selected Bookends items is stored in “theRefsNo”, but is then not used anywhere. So there seems to be no loop, but only one run through the code.

Also, I may have misunderstood how the “selection” of the Bookends entries to be imported is being done. Is it via the checkbox (= Hits list), or is it via clicking on them?

Thanks for your help!

The line is indeed superfluous, but the loop is there! No need to add the entries to the hit list, just leave them selected (e.g. by shift clicking).

Thanks - now it works indeed!

1 Like

I could find this very useful, but two questions.

(1) I can open the it as a Tinderbox file, but how do I import the Stamp/script into an existing TBX file (after making a backup of course)? Ideally importing the minimum necessary to run the stamp.

(2) I see that it places the TBX link into field User8 in Bookends, but one of the limitations of Bookends is that the only field that allows for clickable URLs is “URL”, which is often used for a “real” web link for the reference. So while I could change User8 to URL, I don’t want to do this. This seems to make having the link in Bookends of rather limited use. It seems very long-winded having to use the link by copying it, pasting it into a web browser, and then allowing the browser to open Tinderbox. That works, but is hardly convenient. Have I missed something? Of course it is a Bookends question not a TB one.

Sorry if these are dumb questions.

The file — with the prototype, the script and the stamp — is the bare minimum. The exception being only the Reference note and its children; you can erase them.

Indeed, the use is quite limited, but should you need to find the note quickly, you know where you could.

Let me know if you have other questions, @rogerbackhouse :slight_smile:

Can I ask an unrelated question, Bernardo? (Apologies to followers of this thread!)
I found the demonstration of how you turn Tinderbox notes into LaTeX intriguing, and I am very interested to learn how to do this. (I used LaTeX for a long time for publishing scholarly work, restricting myself to one – Latin – alphabet, though…).
Would you perhaps be willing to write up a brief text on how you do it, and add an example file? Or do an interview with @satikusala in his series of Tinderbox videos? I am confident that would be very positively received in the scholarly subcommunity of the Tinderbox realm.

Sure, @abusch, gladly. I will open another thread about this and post what I have so far for working with Pandoc in Tbx.

1 Like

That would be so kind - and very useful. Much appreciated!

1 Like

I would love to host an interview with @Bernard-0.

2 Likes