Reading named styles off of a cell using JXA


I’m working on a script to convert an OmniOutliner outline of an academic paper to markdown. The plan is to use named styles to indicate cells that need special markdown tags, such as headings (#, ##, etc.) and quotes (>). But I haven’t yet figured out how to access the named styles applied to cells in javascript so that I can include a suitable switch statement such as:

switch(style) {
    case "Heading 1": 
        paperText += "# ";
    case "Quote": 
        paperText += "> ";

Does anyone know how to do this? Thanks!




Just learning JXA, but here is an example of how I got the name of named style of the 8th row (the one colored red) of a document based on the Classic Theme template. --> “Red”.

The way I understand it, a row’s style can contain one or more named styles. This retrieves the name of the first named style.


oo = Application('OmniOutliner');
var frontDoc = oo.documents[0];
var theRow = frontDoc.rows[7];[0].name();


You are awesome, thank you so much. It worked!

Here’s the completed code that assembles a UTF8-encoded string with the text of the entire OmniOutliner document, minus notes/any additional columns. (You have to convert to UTF8 first if you want to pass the string to pandoc.) Now I just need to figure out how to automatically parse italics/bold into the relevant tags…

var OmniOutliner = Application('OmniOutliner');
var doc = OmniOutliner.documents[0];
var paperText = "";

// Loop through rows and append their text to paperText, adding markdown tags for rows based on their named style

doc.rows().forEach(function(theRow) {
    // Check if this row has named styles
	if (Object.keys( > 0) {
            // Just looks at the first namedStyle it finds; won't behave as expected if you apply more than one of these named styles to a row.
		switch([0].name()) {
			case "Heading 1":
				paperText += "# ";
			case "Heading 2":
				paperText += "## ";
			case "Heading 3":
				paperText += "### ";
			case "Blockquote": // Custom named style
				paperText += "> ";
			case "Ordered List": // Custom named style
				paperText += "1. ";
			case "Unordered List": // Custom named style
				paperText += "* ";
	paperText += theRow.cells[1].richText();
	paperText += "\r\r";

// Convert the text of the paper to UTF8 encoding so that e.g. pandoc can read it

paperText = $.NSString.alloc.initWithUTF8String(paperText);


Anyone updated this to the latest OmniAutomation functionality?

I’d like to get the style name, but this is returning “undefined”

rootItem.descendants.forEach(function(item) {
    style =


I worked it out:

rootItem.descendants.forEach(function(item) {
    if (typeof ([0]) !== "undefined") {
        style =  // returns object of type Style
        firstStyle = style.namedStyles[0]  // first named style
        styleName =
        // code block

Caveat: there are potentially several namedStyles. For my use, I just want the first one.