Education > Reference (from Bookends) Script

Hi,

I’ve just started using this in-built script to import the selected reference(s) from Bookends into an RTF note in DT3.

The script works exactly how I’d want it, with one exception: I would like to replace the ‘Year’ in the template, which is currently set to publication year, with another date field, “Read Date”.

Both dates are in the same format, so I think this should just be a straight change of field code in the AppleScript.

The current code for getting the publication date is:

set theYear to getValueFromRIS("PY", theText)

Therefore, all I think I should have to do is replace PY with the correct field code—the rest of the script should be entirely unaffected. My problem is finding out what the correct code should be.

In Bookends, my ‘Read Date’ field is contained in the User18 field, but I can’t discover how that translates into the right code in the AppleScript. I’ve tried “User18” and “u18” and neither work: the template is still produced, but the Read Date line is empty.

So, does anyone know where I can find the list of two letter codes for getValueFromRIS() from? I’ve tried searching on the Bookends site and forum, and in the Dictionary, but have come up with nothing.

I’m obviously missing something obvious, but could some kind soul please point me in the right direction?

Thanks!

user18 isn’t a string; it’s a property. But it appears that’s the PMID from what I see.

tell application "Bookends"
	set sel to item 1 of (selected publication items of library window 1 as list)
	user18 of sel
--> 37111126
end tell

Thanks for the quick reply, Jim.

Unfortunately, I’m not really clued up enough to understand how this would fit in the DT3 script as it stands.

I’m talking about the AppleScript installed by default and found at Data > New from Template > Education > Reference (from Bookends) – I haven’t amended it in any way.

The relevant part of the script appears to be

	set theAuthors to getValueListFromRIS("AU", theText)
	set theTitle to getValueFromRIS("T1", theText)
	set theAbstract to getValueFromRIS("AB", theText)
	set theYear to getValueFromRIS("PY", theText)
	set theNotes to getValueFromRIS("N1", theText)

getValueListFromRIS and getValueFromRIS are defined as:

-- Get values from a RIS-formatted text (RIS is a standard interchange format for references)
on getValueFromRIS(tag, RIStext)
	set theValue to ""
	set theLines to my helperLibrary's split(RIStext, return)
	repeat with theLine in theLines
		if length of theLine > 6 then
			if word 1 of theLine is equal to tag then
				set theValue to my helperLibrary's trim(text 7 through -1 of theLine)
			end if
		end if
	end repeat
	return theValue
end getValueFromRIS

on getValueListFromRIS(tag, RIStext)
	set theValues to ""
	set theLines to my helperLibrary's split(RIStext, return)
	repeat with theLine in theLines
		if length of theLine > 6 then
			if word 1 of theLine is equal to tag then
				if theValues is equal to "" then
					set theValues to my helperLibrary's trim(text 7 through -1 of theLine)
				else
					set theValues to theValues & "; " & my helperLibrary's trim(text 7 through -1 of theLine)
				end if
			end if
		end if
	end repeat
	return theValues
end getValueListFromRIS

So, all the other fields are designated by two-letter codes “AU” for author, “T1” for title and so on.

How would I incorporate the information you gave me into this structure?

Thanks for your help!

Those aren’t value we came up with. They are part of the RIS format. Here’s what I see on it…

There is discussion here: RIS (file format) - Wikipedia.

In Bookends…
File > Import Filter Manager > RIS

Hah, yes, that was the clue!

Basically, I had to:

  1. Amend the RIS.fltr in Import Filter manager to add a two letter code ‘RD’ to the ‘Read Date’ field. (i.e. It uses my ‘display name’ for that field)

  2. Amend the RIS.fmt in Formats Manager to add a new line $RD - $u18 (i.e. It uses the underlying shortcut for the ‘real name’ of the field User18).

But it works now, and I would never have figured this out without your help. Thanks!

1 Like

Glad to help and you pointed out some things I didn’t know about either. :slight_smile:

1 Like

Well, that would be the first time you’ve learnt something from me, rather than the other way round, in the 12 years I’ve been on this forum! :smiley:

Thanks again, Jim!

1 Like