Automation of Scrivener to Word

The purpose of the script is to turn a text document with in-text footnotes, in-text comments, distinct rich-text formatting for headings at distinct outline levels into a nicely formatted document, which uses in-built footnotes, comments, styles and ToC features.

I couldn’t find a way to achieve this with Scrivener and MMD solely, most notably how to get the outline hierarchy from Scrivener to Word. MMD does the trick, but MMD then fails at creating real Word/RTF footnotes and comments. (Or have I been to dumb to figure that out?) So, I use MMD to get the hierarchy exported (well, it is represented by different font styles). For comments and footnotes, I use Scrivener’s features, but still tag them ("[FN: footnote here]")

The script does the following:
Space/new line doublets are replaced by single space/new line.

  • Outline levels of all paragraphs are set to 0, which means: no more garbage in Word’s Document Map.
  • Text with certain formatting is assigned to paragraph styles “Heading 3″, “Heading 2″ or “Heading 3″
  • In-text comments, i.e. text like “[AN: this is an in-text comment]“, are replaced by Word’s colourful comment bubble
  • In-text footnotes, i.e. text like “[FN: this is an in-text footnote]“, are replaced by a real footnotes
  • A table of content is created at a position marked by a certain string.

Find the applescript for Word and a test document (akin to what MMD->RTF compiler produces on my computer) attached.

A complete workflow from Scrivener to Word would now include:

  • Compile with MMD->RTF
  • Open exported RTF in Word
  • (Optional: copy Text from RTF, paste into your templates)
  • Run the script

format document files.zip (14.3 KB)

Thank you hallamann for posting this script. It is has solved a major problem for me! I can now write in Scrivener, and easily export to docx - applying the Word styles to the headers and text as appropriate.

A couple things I noticed I had to do to get the workflow right. Is there a way to script this?

  • After exporting from Scrivener to RTF, I had to highlight all the text in the RTF document (Ctrl-A) and remove all direct paragraph settings (Command-Option-Q).
  • Then I ran your script
  • Then, I had to highlight all text again (Ctrl-A) and remove all direct applied Character settings (Ctrl-Space).

This left me with clean headers without any additional character or paragraph formatting applied.

Also, I found it useful to modify the script to set the Normal style to the body text.

Finally, I have a question for you. The one remaining style I would love to be able to export from Scrivener are my lists. Is there a way to script searching for bullets, deleting those bullets, and then setting the style of that paragraph to say “List”? I’m not familiar with how MMD codes bullets.

Thanks again for writing this.

Have any of you tried using the HTML file that MMD creates? A while back I tried importing an MMD HTML file into OpenOffice.org, and was surprised to find that it converted nearly everything into proper stylesheets. Of course the big exceptions are comments and footnotes, so no extra help there, but as far as lists, headers, and quotations go—that kind of thing—it seemed to be a big step up from trying to work with the RTF.