Set summary type for a new column?


#1

I have a script that creates new columns in OmniOutliner. In the addColumn method, I can specify the type as Number, but is there any way to set the summary type for the column? I’m trying to automate creating a column of type Number with a summary type of Total.

Thanks!


#2

The documentation doesn’t suggest that column summary type is exposed to the omniJS interface, but it is exposed to the JXA (JavaScript for Automation interface), so in Script Editor etc you could run code like:

(() => {
    'use strict';

    // main :: IO ()
    const main = () => {
        const
            oo = Application('OmniOutliner'),
            ds = oo.documents;
        return either(
            alert('OmniOutliner JavaScript for Automation Script'),
            result => console.log(result),
            bindLR(
                0 < ds.length ? (
                    Right(ds.at(0))
                ) : Left('No documents open in OmniOutliner'),
                doc => {
                    const newColumn = oo.Column({
                        name: 'Summing',
                        columnType: 'numeric',
                        summaryType: 'total'
                    });
                    return (
                        doc.columns.push(newColumn),
                        Right('New numeric column, summary type : total')
                    );
                }
            )
        )
    };

    // JXA --------------------------------------------------

    // alert :: String => String -> IO String
    const alert = title => s => {
        const
            sa = Object.assign(Application('System Events'), {
                includeStandardAdditions: true
            });
        return (
            sa.activate(),
            sa.displayDialog(s, {
                withTitle: title,
                buttons: ['OK'],
                defaultButton: 'OK',
                withIcon: sa.pathToResource('OmniOutliner.icns', {
                    inBundle: 'Applications/OmniOutliner.app'
                })
            }),
            s
        );
    };

    // GENERIC FUNCTIONS ----------------------------
    // https://github.com/RobTrew/prelude-jxa

    // Left :: a -> Either a b
    const Left = x => ({
        type: 'Either',
        Left: x
    });

    // Right :: b -> Either a b
    const Right = x => ({
        type: 'Either',
        Right: x
    });

    // bindLR (>>=) :: Either a -> (a -> Either b) -> Either b
    const bindLR = (m, mf) =>
        undefined !== m.Left ? (
            m
        ) : mf(m.Right);

    // either :: (a -> c) -> (b -> c) -> Either a b -> c
    const either = (fl, fr, e) =>
        'Either' === e.type ? (
            undefined !== e.Left ? (
                fl(e.Left)
            ) : fr(e.Right)
        ) : undefined;

    // MAIN ---
    return main();
})();


#3

Ah. Missed it.

It is in the omniJS API too:

editor.setSummaryForColumn()

So, for example:

(() => {
    'use strict';

    // Code for omniJS evaluation context
    const ooJSContext = () => {
        const
            nameOfNewColumn = 'Figures',
            dataTypeOfNewColumn = Column.Type.Number,
            summaryTypeOfNewColumn = Column.Summary.Total,
            editor = document.editors[0],
            outline = document.outline;

        return null !== outline.columns.byTitle(nameOfNewColumn) ? (
            'Column already exists: "' + nameOfNewColumn + '"'
        ) : (
            editor.setSummaryForColumn(
                outline.addColumn(
                    dataTypeOfNewColumn,
                    editor.afterColumn(null),
                    col => {
                        col.title = nameOfNewColumn;
                    }
                ),
                summaryTypeOfNewColumn
            ),
            'Created new column: "' + nameOfNewColumn + '"'
        );
    };

    // JXA code evaluating omniJS Code
    return Application('OmniOutliner')
        .evaluateJavascript(
            '(' + ooJSContext + ')()'
        );
})();