Scripting 'Scan Document' function without invoking UI

Users asking other users for AppleScripts that work with Bookends.
Post Reply
Posts: 2
Joined: Fri Jun 25, 2021 1:26 pm

Scripting 'Scan Document' function without invoking UI

Post by pcon12 »

Over the past 6 months, I've gone all in with writing in plain text/Markdown, and with automating everything that can be. My setup holds text files in DEVONthink, references in Bookends, and is tied together mostly with AppleScript. For example, none of the available Markdown-writing apps handle footnotes in a way that I like, so I wrote a script, using regex, that converts anything contained within backticks to a footnote, when consolidating/exporting my .md files. It works well.

The one part of the process that isn't satisfactorily automated is the final stage where Bookends scans citation markers into formatted citations. I have a Keyboard Maestro macro that runs the 'Scan Document' function via the GUI. However, GUI manipulation is never 100% reliable, and it's preferable to have such processes running in the background, without a window needing to take focus.

Having this run in the background is desirable for a few reasons. First, with any given writing project, I will likely need to export the formatted manuscript at least a dozen times (with the same settings each time). Second, to get a full and accurate word count, it is also necessary to format the document—and this is something I might do 50 or 60 times while editing. Third, processing in the background will likely be significantly faster than bringing several windows into focus and then dismissing them.

So, this post is, in part, a feature request: it'd be great to have full 'Scan Document' functionality as part of Bookends' scripting dictionary! However, I am also exploring how plausible it is to reverse engineer this functionality using the existing toolset.

The easy part is, of course, that the `format` command will return: (1) a bibliography for author-date styles, and (2) the full version of the citation for note styles. However, as far as I am aware, I would have to script the following for myself:

(a) Formatting in-line citations, e.g. (Smith, 2020: 45)
(b) Modify note-style citations to include cited pages, e.g. Smith, Journal of Journal Studies, 'An Article': p.45 <-- this last part would need to be added
(c) Adding ibid or abbreviated version of note-style citation when used more than once

Each should be doable, just time-consuming. Also, it'd need to be updated for each new citation style used. Another consideration is that this approach would not allow for correcting ambiguous citations. However, I've never had to use this feature when using the standard citation markers, containing unique IDs, so that shouldn't be a problem.

Anyway, I basically want to check if I'm missing anything or making things unnecessarily difficult for myself. Has anyone else done this or is it just me, in my madness?

Posts: 14
Joined: Sat Sep 01, 2018 10:42 pm

Re: Scripting 'Scan Document' function without invoking UI

Post by damo.clarky »

Hi pcon12,

Take a look at this thread of discussion I had with Jon quite some time ago. With the latest release '14.1.1 (August 6, 2022)', Jon has added support for:
Use Copy Formatted for citations
Previously Copy Formatted only allowed you to copy the formatted bibliography output.
I checked the Bookends Applescript Dictionary, and format still only produces formatted references. But with support for formatted citations added to the Bookends UI, perhaps Jon could add this to Applescript Dictionary too? Jon, is this feasible and if so, do you have the capacity to entertain it?


Site Admin
Posts: 9588
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD

Re: Scripting 'Scan Document' function without invoking UI

Post by Jon »

Copy Citation Formatted is limited because it can't take into account metacharacter modifications or cited pages, which are pretty much essential when writing a paper. It's intended for interactive use where the user can modify it after it's inserted in the word processor, not for unattended use.

Sonny Software

Posts: 434
Joined: Fri Jan 25, 2008 2:31 pm

Re: Scripting 'Scan Document' function without invoking UI

Post by iandol »

pcon12 wrote:
Tue Jan 18, 2022 10:35 am
is it just me, in my madness?
Madness? I concur! :P

If you are using markdown, why are you not using Pandoc's CSL citeproc engine instead of the [clunky] document scanning? Bookends can output [@citekey] Pandoc citations, and Bookends + Markdown + Pandoc yields a robust and fully automated output without any GUI. I use this for automating compiling to final documents from Scrivener, which simply runs a script that gives me fully-formatted DOCX / ODT / PDF simultaneously without intervention...

Post Reply