A couple of somewhat interesting discoveries

A place for users to ask each other questions, make suggestions, and discuss Bookends.
Post Reply
gshenaut
Posts: 16
Joined: Wed Dec 23, 2009 1:24 pm

A couple of somewhat interesting discoveries

Post by gshenaut »

The general topic is scripting Bookends, which I know from reading the forums is not something that is likely to come anytime soon.

First, I've been playing around with Word fields, mostly with INCLUDETEXT as a way of inserting things like tables and figures into a document. I was annoyed by Bookend's propensity for always putting the bibliography at the end, but in the documentation it says that if you move the bibliography to a different spot and then rescan the document, Bookends "remembers" the new location. Well, that sounded like it was related to Word's concept of fields. Perusing the RTF output of a Bookends scan, sure enough, the bibliography was contained in a field called "ADDIN BB".

I took a raw (unscanned) document, and between page breaks I inserted a References header and a paragraph in the correct style containing only an empty field “{ ADDIN BB }” (Use Command-F9 to insert a field, and just type ADDIN BB into it.) I then scanned the document. Lo and behold, the bibliography was inserted into the field, in the correct location (after the text and before the tables). So, that's pretty cool, in that it eliminates the whole process of shifting the bibliography somewhere else in the document.

Second, I wanted to automate the scan process. SInce there is no Applescript to speak of in Bookends, I was going to use UI scripting, but the problem is that part of the process involves navigating to the file to be scanned, which is almost impossible to do reliably in UI scripting. However, I had noticed that if you started the scan from Word using the “Scan Document” applescript, this step was skipped. So, I examined that script in Applescript Editor, and discovered two things: that Bookends was scanning a copy of the document in the paste buffer, and that it was initiating the scan in response to an AppleEvent. The script has some extra stuff in it to work when initiated from within Word, so I made a slightly different version (called “ScanPB”) that can be run from a script (after copying an RTF file to be scanned into the paste buffer). It looks like this:

Code: Select all

tell application "Microsoft Word"
	run
end tell
tell application "Bookends"
	activate
	«event bepebepb»
end tell
It still pops up the panel giving the scan options, and it still sends the results to Word (hence the "run" command to make sure Word is there). I may be able to use a combination of UI scripting (for the scan options) and applescript (to tell Word what to do with it), but I haven't tried that yet.

Personally, I'm excited by this, since I think it will lead to a much more efficient workflow. I hope that both of these things are reasonably stable in Bookends.

Greg Shenaut
Post Reply