Page 1 of 1

[Return] key in a field of multiple values (AppleScript)

Posted: Fri Apr 01, 2016 1:41 am
by Dellu
The following AppleScript is taken from Tinderbox Forum.

Code: Select all

--sends name, id, url, notes of selected Bookends references to clipboard for pasting into Tinderbox
--other Bookends fields accessible: authors, editors, journal, volume, pages, thedate, publisher, location, title2, abstract, user1...user20
tell application "Bookends"
	set selected_ids to «event ToySRUID» "Selection" --gets ids (line-feed-delimited strings)
	set selected_ids to words of selected_ids --coerces to list
	--"header" row -- these map to (or become new) Tinderbox attribute names:
	set tsv_string to "Name" & tab & "Authors" & tab & "BE_ID" & tab & "URL" & tab & "Text" & return
	repeat with i from 1 to length of selected_ids
		set an_id to item i of selected_ids
		set be_title to «event ToySRFLD» an_id given string:"title"
		set be_author to «event ToySRFLD» an_id given string:"authors"
		set be_uri to "bookends://sonnysoftware.com/" & an_id
		set be_notes to «event ToySRFLD» an_id given string:"abstract"
		--data row: order/number of columns must match header row above
		set tsv_string to tsv_string & be_title & tab & be_author & tab & an_id & tab & be_uri & tab & quote & be_notes & quote & return
	end repeat
	set the clipboard to tsv_string
end tell

The purpose is to push a number of fields including the "Author", "ID", "Abstract" ect to Tinderbox spreadsheet. The script works perfectly except one problem. When the Authors are two and more, the Return key between the Author names breaks the spreadsheet.
Here is the screen shot of two references: first with a single author;

Image

As you can see, all the fields are correctly populated in the above spreadsheet (attribute-value matrix). Now look at with 3 authors:

Image

Now, the fields below the "Authors" field are not populated; and each of the rest of the authors have their own row (note). Is there a way to make the Return key not to cause a break? I mean, in a way, the return key could be neutralized into a single field? or a way to modify the scrip to avoid the break down?

Re: [Return] key in a field of multiple values (AppleScript)

Posted: Fri Apr 01, 2016 8:49 am
by Jon
This is an Applescript issue, not Bookends per se, so you can Google for this sort of thing yourself. I did and there are lots of ways of removing returns from a line. Here's a 4 line snippet that I saw that works with be_author, although I didn't try it with Tinderbox.

set be_author to «event ToySRFLD» an_id given string:"authors" -- in the original script

set AppleScript's text item delimiters to {return & linefeed, return, linefeed, character id 8233, character id 8232}
set newText to text items of be_author
set AppleScript's text item delimiters to {"; "}
set be_author to newText as text

set be_uri to "bookends://sonnysoftware.com/" & an_id -- the original script continues

Jon
Sonny Software

Re: [Return] key in a field of multiple values (AppleScript)

Posted: Fri Apr 01, 2016 9:44 am
by Dellu
Thank you Jon. It was strangely importing the AppleScript itself into the Tinderbox Spreadsheet. But, your script gave me the clue to figure out a way around it. I finally used Keyboard Maestro to Search the clipboard and replace returns with semicolon.

Thank you again.