Writing Fountain-formatted text to a file

Hi there. I’m trying to write a simple OmniJS automation that will take the current outline and output it as a Fountain file – sort of a Markdown variant aimed at screenwriting. I have an action that actually creates the Fountain text correctly (at least, I think I do)…but I can’t figure out what to do with it at that point. The “OmniOutliner: Document Export” page on omni-automation.com doesn’t seem to be helpful for this use case, since I’m not exporting a file type that OO can natively export. The “FileWrappers” and “FileType” doc pages are frankly a little mystifying – and in some cases simply don’t work (i.e., “Creating a FileType Instance” tells you to use fType = new FileType("public.plain-text"), but that gives you a “TypeError: CallbackObject is not a constructor” error on both macOS and iOS).

Any suggestions?

Update: by wrapping the OmniJS in AppleScript, I can copy the Fountain-formatted text to the clipboard. This seems a little suboptimal (and it’s certainly not cross-platform between macOS and iOS, which would be ideal), but it’s the best I can manage so far.

For the record:

set myScript to "var topics = new Array();
var indent = '#';

rootItem.descendants.forEach(function (item) {
	level = item.level;
	itemString = indent.repeat(level) + ' ' + item.topic;
	topics.push(itemString);
	if (item.note) {
		topics.push('= ' + item.note);
	}
});

fountainFile = topics.join('\\n\\n');"
tell application "OmniOutliner"
	set myFountainFile to evaluate javascript myScript
end tell

set the clipboard to myFountainFile

display dialog "Fountain text copied to clipboard."

Perhaps there’s a way to adapt this to Shortcuts for iOS. (The Omni Automation and iOS Shortcuts App page could, ah, use a bit of filling in…)

So, I have a script that actually does what I want using Scripting Additions, prompting to either save to a file or the clipboard. I originally thought it didn’t work at all in OmniOutliner, but that appears to be some kind of strange interaction with Script Debugger when it’s open? I’m not quite sure what’s going on. I’ll update the script here for the ones and ones of other people who might be looking for this functionality when I’m fairly sure it’s consistently doing the right thing.

For the record, anyone looking for a Markdown exporter from OmniOutliner will likely be able to use this, as Fountain uses essentially the same format:

# Act I

## Scene 1

= Synopsis generated from note field

## Scene 2

= Another synopsis