Is there a way to automatically include hyperlink in user field or note?

A place for users to ask each other questions, make suggestions, and discuss Bookends.
Post Reply
postdoctoral
Posts: 23
Joined: Mon Dec 27, 2021 9:38 pm

Is there a way to automatically include hyperlink in user field or note?

Post by postdoctoral »

As the title says: I would like to have the hyperlink to BE (eg bookends://sonnysoftware.com/154243) for a given reference be included with the reference material itself, either in a user-defined field of the reference pane, or in the note tab. This is so that other applications that pull this data can send me back to BE when I want to.
I know that you can do this manually for each entry, but I'm a bit too far along for that to be an attractive option.
My questions:
1) is there a way to batch process this for my existing library?
2) is there a way to make it part of the default for new entries?
Thanks in advance!
iandol
Posts: 481
Joined: Fri Jan 25, 2008 2:31 pm

Re: Is there a way to automatically include hyperlink in user field or note?

Post by iandol »

At least good news here. Applescript can read and write information from the database, so it is possible to create a script that would iterate through each reference and write a URL with the unique ID to a user field or appended to the notes field. Read the "Scripting Bookends" chapter in the user manual or this page: https://www.sonnysoftware.com/scriptingbookends/ — I don't have so much time now but if I can find an existing script rattling about that does something similar I can adapt it fairly quickly, but it may be a good learning experience otherwise...
iandol
Posts: 481
Joined: Fri Jan 25, 2008 2:31 pm

Re: Is there a way to automatically include hyperlink in user field or note?

Post by iandol »

This applescript will take selected refs and add the bookends:// link to a new note: — I used a selection deliberately so you can choose which refs to operate on, if you want a nuclear option just remove the word "selected":

Code: Select all

tell application "Bookends"
	tell front library window
		set myRefs to selected publication items
		repeat with myRef in myRefs
			set thisNote to notes of myRef
			set thisID to id of myRef
			set thisURL to "bookends://sonnysoftware.com/" & thisID
			set thisNote to thisNote & linefeed & linefeed & thisURL & linefeed
			set notes of myRef to thisNote
		end repeat
	end tell
end tell
You could change it to add to e.g. user20 like so:

Code: Select all

tell application "Bookends"
	tell front library window
		set myRefs to selected publication items
		repeat with myRef in myRefs
			set thisURL to "bookends://sonnysoftware.com/" & id of myRef
			set user20 of myRef to thisURL
		end repeat
	end tell
end tell
It could also be modified to make a markdown link but I suspect Obsidian renders raw links as clickable?
postdoctoral
Posts: 23
Joined: Mon Dec 27, 2021 9:38 pm

Re: Is there a way to automatically include hyperlink in user field or note?

Post by postdoctoral »

This is great, thank you so much!I’ll read the chapter and play around and tweak the script for my needs.

This script is to be run manually as a one-off to put the URL where I want it across my whole library (or set, as you say) — but new refs would still have to be finished up manually, though, correct?

Expanding on this, I think it would be neat if there was a baked-in option to put the link somewhere in the reference fields. Just like there is an option to assign a Bibtex ID to a new reference, there could be a simple tick box that said “Place clickable Bookends URL link in User20 field” or something like that.
I could see myself using such a function in conjunction with the linked .bibtex file. Bookends will always be the keeper of my PDFs and their annotations, but the .bibtex file is becoming more and more a gateway to that information that I share with other apps. The ability to jump back to Bookends and thus to the annotated PDF would be awesome. Especially since these URLs work so well on iPad OS — whereas linking directly to the PDF’s location in iCloud Drive is (to my knowledge) a mighty mess in iPad OS.
iandol
Posts: 481
Joined: Fri Jan 25, 2008 2:31 pm

Re: Is there a way to automatically include hyperlink in user field or note?

Post by iandol »

Correct, this is manual. You could "automate" this with launchd or some other tool so that it runs every X hours, but if you wanted it to be fast (only work on new refs) the script would have to become more complex.

Jon will have to reply on the idea of optionally adding self-links to a user field on import, I think it is a good idea and I'd probably use it personally, but Jon needs to balance filling prefs with a new option vs. the feature utility and generality 8)
Jon
Site Admin
Posts: 10291
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Is there a way to automatically include hyperlink in user field or note?

Post by Jon »

You can generate the links on demand, and you can include them in your BibTeX export already, if that's what you want. In the format (BibTex, or whatever) you'd include this

$bookends://sonnysoftware.com/$=

and Bookends would output the string plus the unique id (that's what the = is for).

Jon
Sonny Software
postdoctoral
Posts: 23
Joined: Mon Dec 27, 2021 9:38 pm

Re: Is there a way to automatically include hyperlink in user field or note?

Post by postdoctoral »

this is very helpful. Thank you!
Post Reply