Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Accessing Bookends Data (Read 15591 times)
Sumner Gerard
Full Member
*
Offline



Posts: 359

Accessing Bookends Data
Oct 21st, 2012, 1:04am
 
Edited:
By admin: I've split this off as it answers a different question to the one originally posed. This AppleScript here is interesting but solves a different problem so deserves it's own thread.


Edited:
By poster: The original thread is here.  There was discussion of Tinderbox having "as the text the contents of the BE notes field" and flexibility as to information brought in from Bookends. Also discussion of linking "to within text" What follows addresses those two points. It has nothing to do with Tinderbox "Agent, Actions, and Rules" (in fact it has none) and a lot to do with the original topic: flexible integration and interaction between Tinderbox and Bookends.


Wish I could see the tantalizing missing pieces (using action code to create weblinks sounds interesting..) but thanks to both for this most useful thread.  Really helped in understanding how Tinderbox and Bookends can work together.

Quote:
…AppleScript won't help in this instance, though the suggestion is welcomed, as the problem boils down to pasting a hyperlink within $Text.


Edited:
This discusses what is effectively a link to within $Text, presumably similar to the Keyboard maestro discussed in the original thread.

Here's the AppleScript way to do essentially the same thing (I'm guessing) as the unseen Keyboard Maestro macro. Fire up Automator, File/New, choose Service, create as below, and save it as "Go to Bookends" or whatever:



Thereafter, run the script from the Services menu after selecting a Bookends six-digit id in the text of a Tinderbox note.  Assign a keyboard shortcut, if wanted, in System Preferences/Keyboard/Keyboard Preferences.

AppleScript is a good solution if some variation is needed on the information brought into Tinderbox in the first place. Say, for example, you really, really want to include your Bookends "notes"  Edited:
(including notes was prominent in the original "off the wall" discussion, and what follows addresses that question directly)
and don't really want some of the other fields in the drag-and-drop. You can quite easily get exactly what you want. Here's how you access the contents of a Bookends field in AppleScript (the BE user guide seems to have the wrong script):

Code:
tell application "Bookends" to return «event ToySRFLD» unique_id given string:target_field
 



where unique_id is the six-digit number, and target_field can be one of the following values: authors, title, editors, journal, volume, pages, thedate, publisher, location, url, title2, abstract, notes, user1...user20

So, let's say you just want to bring into TB the reference title, notes, id, and the link back to Bookends. You can paste something like this into AppleScript Editor and modify to your needs:

Code:
--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 & "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_uri to "bookends://sonnysoftware.com/" & an_id
		set be_notes to «event ToySRFLD» an_id given string:"notes"
		--data row: order/number of columns must match header row above
		set tsv_string to tsv_string & be_title & tab & an_id & tab & be_uri & tab & quote & be_notes & quote & return
	end repeat
	set the clipboard to tsv_string
	display dialog "Ready to paste Bookends references onto a Tinderbox view." buttons "OK" default button "OK"
end tell
 



When running this script, you can select multiple Bookends references at a time. If you have a named group you can substitute its name for "Selection." You can also use "All", "Hits", and "Attachments", though I'm not sure what "Attachments" does. I think it just includes all references that happen to have attachments.
Back to top
 
« Last Edit: Oct 21st, 2012, 6:10pm by Sumner Gerard »  
  IP Logged
Ted Goranson
Full Member
*
Offline



Posts: 141
Virginia Beach VA
Re: Accessing Bookends Data
Reply #1 - Oct 22nd, 2012, 8:24am
 
Sumner —-

What your AppleScript seems to do is construct a URL each time, follow it and then throw it away. Running from the services menu is a big pain for me.

What my Keyboard Maestro macro does is turn the text into a permanent link that you can then click any time you wish. I don't know how to post the image of the code.

But the macro is simple. Place your cursor in the reference number and hit the assigned key trigger. The macro then:

— doubleclicks to select the number
— Copies it
— Selects "Create Web Link..." in the menu
— Insert text "bookends://sonnysoftware/com/
— paste the number
— hit return

end

It happens so fast you can barely see the dialog open and close.

(I usually do some formatting after these, but not here yet.)

The result is that the number is now and forever the link I wanted.

I use KM for a variety of small but handy modifications to the TBx UI.
Back to top
 
 
WWW TedGoranson   IP Logged
Sumner Gerard
Full Member
*
Offline



Posts: 359

Re: Accessing Bookends Data
Reply #2 - Oct 22nd, 2012, 5:06pm
 
Thanks, Ted.  Glad you found this here among "Agent, Actions, and Rules", although there is neither agent, nor action, nor rule.  You've really got me intrigued about KM. Will have to look into it...while reserving room in the Mac software budget for Eastgate, of course!

The AppleScript approach (which doesn't have to be a Service–change one line and it can run from anywhere) requires selecting any BE id number in the $Text of a Tinderbox note, then hitting the assigned keyboard shortcut to instantaneously call up the associated Bookends record. No dialogs open and close; "System Events" goes straight to BE.

It sounds as if with KM after you've set up a "link" from a particular id number once in $Text, you thereafter don't have to select the id number but can just click on it, as if it were a hyperlink. Neat.
Back to top
 
« Last Edit: Oct 22nd, 2012, 5:09pm by Sumner Gerard »  
  IP Logged
Ted Goranson
Full Member
*
Offline



Posts: 141
Virginia Beach VA
Re: Accessing Bookends Data
Reply #3 - Oct 22nd, 2012, 9:15pm
 
It makes sense for the topic to be here, as this is clearly the code/automation area.

The KM macro has another advantage in that you don't have to select the reference's number. You just place your cursor somewhere in it. I'm pretty skeptical of Applescript doing much good with TBx and expect to do all the things I need by other means.

KM allows you to create a floating palette and it is where I keep all my TBx macros, excepting this one (because I'd have to move my cursor off the number).

In particular, it gets heavy use in helping me type complex TBx macros that are used in export. For these, I do automatically shade them out with a highlight and reduce the text size a bit after constructing the macro.

One key feature I like is the ability to take text on the clipboard and run a BBedit text factory on it before pasting back. I use this to solve the problem that TBx doesn't automatically use typographer's quotes, for example, and in assembling macros.

(One place I do use AS and an automator service is in Bookends, where I often want titlecase. The supplied service (which may have come from Devon) doesn't work right. But wrapping John Gruber's code for this (which I think is Perl) in an automator service and triggering from KM is used in this period of my life dozens of times a day.)
Back to top
 
 
WWW TedGoranson   IP Logged
Sumner Gerard
Full Member
*
Offline



Posts: 359

Re: Accessing Bookends Data
Reply #4 - Oct 23rd, 2012, 12:13am
 
If this section is to be home to threads like this, maybe it should be called Code/Automation. There is no "Need a hand with getting an agent to do exactly what you want" (Agent, Actions, and Rules) in this thread. It certainly wouldn't be a place I'd naturally think of browsing if I was looking for something on Bookends or AppleScript. On the other hand, there is definitely a bit of "can't quite figure out how to do something? Here's the place" (Off the Wall) or "approaches to different tasks" (Tinderbox applications).

Anyway, thanks for the fascinating glimpses of how you're using KM with Tinderbox! Definitely will look into it.

I wouldn't be too skeptical about AppleScript, though. I may be suffering from the "to the person with a hammer every problem is a nail" syndrome, but in just a few weeks I truly have been astonished how AppleScript has become immediately useful in integrating Tinderbox with other Mac apps.  Tinderbox may not have a "suite" in the AppleScript Dictionary, but it can do a lot more with AppleScript in accomplishing practical tasks than many of us may have been assuming. It does just fine in passing attribute values into scripts, and on the inbound side Tinderbox's "spreadsheet import" of AppleScript-generated tab-separated-values is great--in many cases eliminating the need to save/import files and pre-stage the TBX by first creating user attributes, etc.  Just run and paste, and Tinderbox does the rest.

The following isn't the best example of the real power, because of its reliance on gui scripting (where presumably KM excels). Rather it's a quick demonstration of something more similar to your KM macro (as I understand it) than my last offering.  (I worked it out before I saw your last post).

Code:
on run
	activate application "Tinderbox" -- make Tinderbox frontmost
	delay 0.2
	tell application "System Events" to tell process "Tinderbox"
		keystroke "c" using command down
		delay 0.1
		set be_id to return the clipboard as text
		set be_uri to "bookends://sonnysoftware.com/" & be_id
		click menu item "Create Web Link…" of menu "Note" of menu bar item "Note" of menu bar 1
		delay 0.1
		keystroke be_uri & return
	end tell
end run  



This turns any selected Bookends id number in $Text into a permanent clickable link (i.e. after the link is created, don't have to first select the entire number) to the specific Bookends reference. It can be pasted into a service and assigned a keyboard shortcut, or run from somewhere else convenient.
Back to top
 
« Last Edit: Oct 23rd, 2012, 12:20am by Sumner Gerard »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Accessing Bookends Data
Reply #5 - Oct 23rd, 2012, 5:35am
 
The latter script goes much closer to addressing the issue raised by @Ted in his feature request. I'd suggest this a an alternate (noting @Ted already has a workaround with KM). In BE, by default, Shift+Opt+Cmd+L copies the desired BE back-link URL to the clipboard as text. So either copy past anchor text of citation from BE or type it in TB $Text and select it. In BE, load the URL (Shift+Opt+Cmd+L) then run the AppleScript below via automation of your choice (Stamp using runCommand(), an Automator service, etc.):


Code:
on run
	activate application "Tinderbox" -- make Tinderbox frontmost
	delay 0.2
	tell application "System Events" to tell process "Tinderbox"
		keystroke "c" using command down
		delay 0.1
		set be_uri to return the clipboard as text
		click menu item "Create Web Link…" of menu "Note" of menu bar item "Note" of menu bar 1
		delay 0.1
		keystroke be_uri & return
	end tell
end run   



I'd stress this an alternate to some of the up-thread ideas. Users will pick what suits them; for instance if I were a keyboard-centric type and had KM I'd go with @Ted's solution.

Still unresolved by the latter is getting the correct anchor text (as correct citation info may not be to mind when typing in TB. In that case, @Ted has shown (off forum) that by making a custom format in BE you can customise what's pasted in a citation link. Let's say you want anchor text in TB of the form "(author, year)", then if you could make BE load "(author, year)ID#" that could be pasted into TB $Text, the BE ID# selected, cut to the clipboard and then use the script in @Sumner's last post (the one preceding this).

Of course, the ideal solution is for TB $Text to be able to read a URL + anchor text combo on the clipboard and paste it as a TB web link. However that needs engineering in TB so isn't today's answer (i.e. as at v5.11.2).
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Accessing Bookends Data
Reply #6 - Oct 23rd, 2012, 5:42am
 
In my admin 'hat' a few observation re threads and comments made in this one:
  • I've amended this sub-forum's titles to "Agent, Actions, Rules & automation". This is the best place to discuss TB automation in whatever form - certainly for longer term users.  New users may well post in the Q& A. whether it's a rule, action or shell command is really immaterial, what we're discussing here is automating Tinderbox. Have even more sub-fora, e.g. for just shell scripting, isn't really needed as the latter invariably also involve TB internals at some point.
  • The forum staff can't win on titling. The forum "off the wall" was so titled as people misunderstood the previous title "Feature" Requests" and got way too personal about response to/ownership of ideas there.  The aim of that forum is both to ask for features the user needs (ideally with some rationale as to why) or to ask if something id possible with the implicit aspect that if not, can it be a feature request.
  • The latter do occasionally lead to discussion of a solution or workaround. This is not to gainsay the suggestions but simply reflect that engineering in the app is rarely instant whereas the posts in that forum are often driven by a task the user is trying to do today.
  • The TB applications forum was (is) really intended for more complete topics, either the use of the app in the context of [some activity], e.g. writing a novel, making an index, making a syllabus, etc., or presenting TBX that are effectively a complete solutions. Smaller-scope solutions such as discussed here, are better placed here or in the export forums.
  • This thread was split from the original one for the valid reason that whilst the AppleScript method worked, it solved a different problem to the one the thread raised. When threads are split or moved the forum software makes cross-links so it's simply not true to imply the moved content has been hidden.
  • When splitting a thread, it often them makes sense to re-title the thread to reflect the narrow topic. In such case, as the admin can't add a discrete new post as #1, they enter a short explanatory post into item #1 in the thread explaining the reason for the slip. No censure is implied - thread drift isn't intentional, it just happens.
  • We should remember that the value of a resource like this forum is not just the current debate but its use to those reading it at a later date. The latter are not well served by meandering threads.
  • If you feel the admins' actions are egregious please contact him/her privately. If things gets uncivil, everyone loses.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Sumner Gerard
Full Member
*
Offline



Posts: 359

Re: Accessing Bookends Data
Reply #7 - Oct 23rd, 2012, 7:50pm
 
Quote:
@Ted has shown (off forum) that by making a custom format in BE you can customise what's pasted in a citation link

Ah, that sounds promising, in many cases easier than using AppleScript on the BE end. AppleScript there may be a more natural solution (maybe the only solution) when lots of customization is desired, such as automatically bringing over BE notes into Tinderbox, as in the last script in the first post above.

Quote:
via automation of your choice (Stamp using runCommand(), an Automator service, etc.):

Mark, I think that any AppleScript with gui scripting (i.e. the last two scripts, not the one in the first post that extracts data from BE) is not a good candidate for "Stamp using runCommand()" because osascript seems to grab the frontmost status and won't give it back to Tinderbox even if the AppleScript tells it to do so. If your experience is different or anyone knows or figures out the answer to that little puzzle, would love to know, just as a point of curiosity. And a hard-won tip to anyone mystified by a completely non-gui script that runs just fine in AppleEditor or in an Automator Service but does nothing when run via runCommand():  eradicate single quotes (apostrophes) in the script, even in commented lines.

Quote:
The TB applications forum was (is) really intended for more complete topics

Thanks for clarifications. As my own files prove, classification and titling is tough. Sometimes, I'm sure, you wish the forum could accommodate Tinderbox-style aliases to keep everyone happy!  In my mind some of the most valuable parts of discussion here go beyond a narrow Tinderbox automation task, and focus on how best to use Tinderbox with other apps, such that Tinderbox does what it does best while taking advantage of what other apps do best. If not suitable for the "TB Applications" section perhaps ideas along these lines could be put in a section titled something like "Using Tinderbox with other apps." I've stumbled across a number of other "Tinderbox with other Apps" practical solutions that may be helpful.
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Accessing Bookends Data
Reply #8 - Oct 24th, 2012, 3:31am
 
The point is well made re app focus when using scripts. I don't doubt your findings. It's an all too familiar scenario for inter-app work. No one piece is doing anything wrong, but also not all are running to the same set of design assumptions! I suspect it's trial and error. Re osascript. My guess (untested) is that TB is already 'running' the script so can't switch back to itself, or at least in the way we intend. With issue involving AppleScript, I find the MacScripter.net forums useful as often there's someone whose tripped over the issue and has an un-guesable solution. Still, workarounds by their very nature tend to be messy!
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Desalegn
Full Member
*
Offline



Posts: 78
Norway
Re: Accessing Bookends Data
Reply #9 - Mar 29th, 2016, 8:12am
 
Hey guys. I am trying to use these scripts. I like the fact that the Notes are imported as $Text.  The latter ones are not working for me (I run my these scripts in Keyboard Maestro; by triggering with keyboard shortcuts).
The first one is working.

But, I want to get the Authors and Date fields included. I JUST DON'T KNOW HOW APPLESCRIPT WORKS.
here is what I was trying to do with no luck:

Code:
--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 & "Author" & tab & "Year" & 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_authors to «event ToySRFLD» an_id given string:"authors"
		set be_date to «event ToySRFLD» an_id given string:"date"
		set be_uri to "bookends://sonnysoftware.com/" & an_id
		set be_notes to «event ToySRFLD» an_id given string:"notes"
		--data row: order/number of columns must match header row above
		set tsv_string to tsv_string & be_title & tab & be_authors & tab & be_date & an_id & tab & be_uri & tab & quote & be_notes & quote & return
	end repeat
	set the clipboard to tsv_string
	display dialog "Ready to paste Bookends references onto a Tinderbox view." buttons "OK" default button "OK"
end tell 



Can you help me modify it?

The other change I would like to make, if possible, is to avoid "imported spreadsheet" container; and import the note directly to the view.
Back to top
 
« Last Edit: Mar 29th, 2016, 8:16am by Desalegn »  
  IP Logged
Pages: 1
Send Topic Print