Scripting 'Scan Document' function without invoking UI
Posted: Tue Jan 18, 2022 10:35 am
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?
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?