Scripting and Scrivener

Lu
LuckyJack
Posts: 37
Joined: Thu Aug 24, 2017 2:39 am
Platform: Mac + iOS

Sat Sep 30, 2017 2:50 am Post

Not screenplay scripting, Python or Perl or various Apple tools. One of the things I appreciate about L&L is how open they are about things like the XML used for projects. It's simple enough to figure out, but I found L&L very open about details, too.

My latest fun-and-games with Python has been for outlining.

I outline in Omnioutliner. Why? It works, I can export to OPML, and Scrivener will import OPML.

Basically, once my outline is finished, I add top-level topics to match what I’d like to see in the binder, and drag existing topics under the new top-level headings.

Then I export to OPML where a short Python script reads the OPML from Omnioutliner and flattens it so the top-level topics are the only topics retained. All the sub-topics and their notes become just a single level of notes in the top-level topics, the ones I decided needed to be in the binder.

That OPML file is imported into Scrivener, with the option to put outline notes into the synopsis cards. A clean binder from an outline with many levels.

In Scrivener, outline mode in the left edit window showing the binder title and the synopsis, locked to the document in the right window, and I’m off and writing. The documents are all blank and ready, my outline is in the left window with my game plan, and the binder isn’t cluttered up with all my parenthetical subtopics.

Anybody else mess with automation like this? Scrivener’s project.scrivx file is really simple. If you can code a little Python, Java, Perl, whatever, you can even build your own. I once wrote a sync script that peeled out all the documents in a Scrivener project and copied them as individual RTF files named by sequence number and binder entry to a usb stick. Then I could edit them on my Android. My little sync gizmo would then read back the RTF files, including new ones and taking note of deleted files, and build a new project.scrivx. Better to use the IOS version of Scrivener, of course, but that was in the old days and it filled a need at the time.

JJ
JJSlote
Posts: 419
Joined: Tue Oct 26, 2010 5:44 pm
Platform: Windows
Location: NY, USA              Docs in Binder: 9800+

Sun Oct 01, 2017 11:36 pm Post

Yes, I've done quite a bit of scripting for Scrivener in Windows, with AutoHotkey, which is very strong in automated button-pushing and screen-scraping. The transparency of Scriv's XML-based binder file format makes the automation manageable, as you observe. My primary script reads the .scrivx into a Listview allowing a sort on the displayed fields, including user fields added through Document Refs and Custom Meta. I can double-click on an entry in the Listview to open the corresponding document in Scrivener, or multi-select a group of documents, including search results, for a hover preview.

That script isn't shareable, but a starter script in AutoHotKey is here:

Toolbar overlay, with "Char Map" & "Reveal in Binder"

Rgds - Jerome

User avatar
nontroppo
Posts: 733
Joined: Mon Mar 05, 2007 5:22 pm
Platform: Mac
Location: Airstrip One

Mon Oct 02, 2017 11:13 am Post

Not by me, but mnott made this alternative compile system:

https://github.com/mnott/texdown

It parses the XML to extract all docs for compiling, extracts the plain text from the RTF files and does custom markup transformation. This demonstrates the amazing flexibility of Scrivener's project format.

On my to-do list is to make a custom compile system that takes all named snapshots and compiles them to a combined document. If you work using named snapshots of all documents, it gives you a way to "extract" a named version from your snapshot history. texdown does most of what would be needed so I could use it as a base, though I'd prefer to use Ruby rather than Perl. But my to-do list is long and my time is, as for us all, limited...

Lu
LuckyJack
Posts: 37
Joined: Thu Aug 24, 2017 2:39 am
Platform: Mac + iOS

Tue Oct 03, 2017 1:50 pm Post

Nice - a standalone compiler. That's awesome. If Version 3's compile is weak, then the use of real style sheets might make alternative compile a real possibility. Pandoc probably has a lot of the hard work done, although I've never used it beyond a little fiddling around.