To add a custom pop-up column to an OmniOutliner document:
by providing the omniJS scripting interface with:
- a column name,
- and a list of pop-up option strings
we could use define ourselves a general function with some name like
popUpColumnFromNameAndValues
and use it in a pattern like this:
// main :: IO ()
const main = () => {
const
newPopupColumn = popUpColumnFromNameAndValues(
"Letter code"
)([
"Alpha",
"Beta",
"Gamma",
"Delta"
]);
// See if all the pop-up options are in place:
return newPopupColumn.enumeration.members
.map(member => member.name)
.join("\n");
};
For a full definition of that kind of function, and a test snippet to paste and enter in the OmniOutliner Automation console:
OmniOutliner > Automation > Show Console
- Expand the disclosure triangle below,
- and click the
Copy
icon at the top right of the code listing that appears.
JavaScript Test Snippet for Automation Console
/* eslint-disable no-console */
/* eslint-disable no-undef */
(() => {
"use strict";
// CREATING A NEW POPUP COLUMN
// WITH A GIVEN NAME AND PRE-POPULATED OPTIONS
// Rob Trew 2021
// Ver 0.01
// main :: IO ()
const main = () => {
const
newPopupColumn = popUpColumnFromNameAndValues(
"Letter code"
)([
"Alpha",
"Beta",
"Gamma",
"Delta"
]);
// See if all the pop-up options are in place:
return newPopupColumn.enumeration.members
.map(member => member.name)
.join("\n");
};
// ------------------ OMNI OUTLINER ------------------
// popUpColumnFromNameAndValues :: String ->
// [String] -> Column
const popUpColumnFromNameAndValues = name =>
values => {
const
outline = document.outline,
editor = document.editors[0];
return outline.addColumn(
Column.Type.Enumeration,
editor.afterColumn(
// After the last column.
last(columns)
),
col => {
const
enumeration = col.enumeration,
checkedValues = values.flatMap(
k => (
enumeration.add(k),
enumeration.memberNamed(k) ? (
[k]
) : []
)
);
return (
// In OmniOutliner,
col.title = name,
// and in the JavaScript Console.
console.log("Popup:", name),
console.log(
"Values:",
checkedValues.join("\n")
)
);
}
);
};
// --------------------- GENERIC ---------------------
// last :: [a] -> a
const last = xs =>
// The last item of a list.
0 < xs.length ? (
xs.slice(-1)[0]
) : null;
// MAIN ---
return main();
})();