Integrating Scrivener with Devonthink and Bookends

In order to integrate my wordprocessor of choice (Scrivener) with DTPO and Bookends more closely, I wrote the following script (borrowing from several others, especially from this [url]Put RTF link(s) to selected documents on the clipboard] by Korm). Often it is the case that I do not remember what the cited reference was exactly about. This script automatically links the references in Scrivener to Bookends and – when the respectivce link in Bookends is present (see my script here:[url]Linking Bookends entries and pdfs in Devonthink]) - also to the document in DTPO. Then only the reference has to be clicked to find the entry in Bookends (or DTPO).
It will copy the selected reference in Bookends, switch to Scrivener and paste the unformatted reference to the cursor position. In doing this it will link the Bookends-ID to Bookends and the group “Author Year” to DTPO (I store the DTPO-reference-URL in Bookends in userfield-20).
The unformatted link looks a little bit different than the normal output from Bookends, but Bookends does not seem to have a problem to still identify the correct reference when formatting the bibliography. However, before the Scan-command can be invoked the document has to be stripped from all hyperlinks. The easiest way to do this seems to be in Microsoft Word (crtl-6) but I would be eager to hear about other solutions.
My only aesthethic problem with the script is that diacritic letters look awful. Somewhere along the script letters like “ä”, “ö”, “ø” etc. are changed in something like “ö”, despite the fact that the shell script retains the RTF-format. Perhaps anyone knows of an easy way to remedy this?

Every hint is appreciated.

Cheers,

Nils

tell application "Bookends"
	set theIDString to «event DNtpRUID» "selection"
	set theauthor to «event ToySRFLD» theIDString given string:"authors"
	set theyear to «event ToySRFLD» theIDString given string:"thedate"
	set devonthinkReference to «event ToySRFLD» theIDString given string:"user20"
	set authorYear to theauthor & ", " & theyear as string
	if devonthinkReference is "" then
		set theReference to "{" & authorYear & ", #" & ("<font face=\"times new roman\"><a href=\"" & "bookends://sonnysoftware.com/" & theIDString & "\">" & theIDString & "</a></font>") & "}"
	else
		set theReference to "{" & ("<font face=\"times new roman\"><a href=\"" & devonthinkReference & "\">" & authorYear & "</a></font>") & ", #" & ("<font face=\"times new roman\"><a href=\"" & "bookends://sonnysoftware.com/" & theIDString & "\">" & theIDString & "</a></font>") & "}"
	end if
	set RTFtheReference to (do shell script "echo " & quoted form of theReference & " | textutil -stdin -stdout -format html -convert rtf | pbcopy -Prefer rtf")
	
end tell

tell application "Scrivener"
	activate
end tell

tell application "System Events"
	key code 9 using {command down} -- v key
end tell
1 Like

I currently have the scripting knowledge of a brick [hoping to remedy that in the near future!] :slight_smile:

I just wanted to thank you for this - I’ve have merely bookmarked this thread, and will come back to it in due time when I start the writing process.

I currently use DTP, and have purchased BE12 and Scrivener to take care of the referencing and writing of my dissertation - so this will no doubt be of great use in the (hopefully) not-to-distant future!

You are very welcome! But please make sure that the scripts work as expected before you rely too heavily on them. I would hate to be responsible for spoiling your dissertation … :confused:

Cheers,

Nils

mueller-scheessel,

I want to reiterate what Cassady said. Thank you!

This is pretty old, but I was wondering if anyone managed to find a solution to the diacritics problem.:slight_smile:

This is pretty old, but I was wondering if anyone managed to find a solution to the diacritics problem.

I have found a solution years ago and have posted it in the Bookends forum but forgot to update it here. This is the updated version:

    tell application "Bookends"
	set theIDString to «event DNtpRUID» "selection"
	set theauthor to «event ToySRFLD» theIDString given string:"authors"
	if theauthor is "" then
		set theauthor to «event ToySRFLD» theIDString given string:"editors"
		if theauthor is "" then
			set theauthor to "Anon."
		end if
	end if
	set theyear to «event ToySRFLD» theIDString given string:"thedate"
	set devonthinkReference to «event ToySRFLD» theIDString given string:"user20"
	
	set oldDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to linefeed
	set theauthorList to every text item of theauthor
	set theauthorListCount to length of theauthorList
	set AppleScript's text item delimiters to ", "
	set ErsterAutor to (first item of theauthorList as string)
	set theauthorVollname to every text item of ErsterAutor
	if theauthorListCount = 1 then
		set theauthor to (first item of theauthorVollname as string)
	else if theauthorListCount > 2 then
		set theauthor to (first item of theauthorVollname as string) & " u. a."
	else if theauthorListCount = 2 then
		set ZweiterAutor to (second item of theauthorList as string)
		set theauthorVollname2 to every text item of ZweiterAutor
		set theauthor to (first item of theauthorVollname as string) & "/" & (first item of theauthorVollname2 as string)
	end if
	set AppleScript's text item delimiters to oldDelimiters
	
	set authorYear to theauthor & ", " & theyear
	if devonthinkReference is "" then
		set theReference to "{" & authorYear & ", #" & ("<font face=\"times new roman\"><a href=\"" & "bookends://sonnysoftware.com/" & theIDString & "\">" & theIDString & "</a></font>") & "}"
	else
		set theReference to "{" & ("<font face=\"times new roman\"><a href=\"" & devonthinkReference & "\">" & authorYear & "</a></font>") & ", #" & ("<font face=\"times new roman\"><a href=\"" & "bookends://sonnysoftware.com/" & theIDString & "\">" & theIDString & "</a></font>") & "}"
	end if
end tell

set RTFtheReference to (do shell script "echo " & quoted form of theReference & " | textutil -stdin -stdout -inputencoding utf-8 -format html -convert rtf | pbcopy")
tell application "Scrivener"
	activate
end tell

tell application "System Events"
	key code 9 using {command down} -- v key
end tell

Thank you very much, @mueller-scheessel!
In case you have posted elsewhere other tips or workflows to work with DT, Scrivener and Bookends alongside, I would be very grateful if you could share them.

Also, do you know by chance if Korm has updated his script as well?

Thanks again!