Fairly arduous, particularly in that coding style.
If you were going to apply styles from omniJS, there would be less typing and more room for flexibility if the name ⇄ value pairs were just kept as a JavaScript dictionary:
Instead of:
Typing-intensive code shown on omni-automation style page
aStyle.set(Style.Attribute.FontCondensed, false)
02 aStyle.set(Style.Attribute.FontFamily, 'Helvetica Neue')
03 aStyle.set(Style.Attribute.FontFillColor, Color.white)
04 aStyle.set(Style.Attribute.FontFixedPitch, false)
05 aStyle.set(Style.Attribute.FontItalic, true)
06 aStyle.set(Style.Attribute.FontName, 'Helvetica Neue Medium Italic')
07 aStyle.set(Style.Attribute.FontNarrow, false)
08 aStyle.set(Style.Attribute.FontSize, 14)
09 aStyle.set(Style.Attribute.FontStrokeColor, Color.red)
10 aStyle.set(Style.Attribute.FontStrokeWidth, 2)
11 aStyle.set(Style.Attribute.FontWeight, 6)
A simpler and more readable JS ‘dictionary’ of key-value pairs would be:
const styleProperties = {
FontCondensed: false,
FontFamily: 'Helvetica Neue',
FontFillColor: Color.white,
FontFixedPitch: false,
FontItalic: true,
FontName: 'Helvetica Neue Medium Italic',
FontNarrow: false,
FontSize: 28,
FontStrokeColor: Color.red,
FontStrokeWidth: 2,
FontWeight: 6
};
and a reusable (copy/pasted) helper function could directly apply all these settings to the the styles of selected items.
The reusable helper function might look like:
// GENERAL AND RE-USABLE HELPER FUNCTION
const setStyleProperties = dictKeyValues => styleObject => {
Object.keys(dictKeyValues)
.forEach(
k => styleObject.set(
Style.Attribute[k],
dictKeyValues[k]
)
)
};
and returning to the suggestion:
There is a lot of fiddle and technical detail in setting those things up, not a low enough cost/benefit to be done very lightly or on the fly, and they are only really needed to cope with the limitations of iOS.
On macOS, much simpler and quicker to drop some code into a Keyboard Maestro ‘Execute JavaScript’ action, and assign a keystroke to it.
This, for example, could be run that way:
Sample macro - apply style in OmniOutliner.kmmacros.zip (10.6 KB)
(() => {
'use strict';
// Run from Script Editor
//
// Or paste into a Keyboard Maestro Execute JXA action,
// and a assign a keystroke.
//
// ( Uses JavaScript for Automation to run an OmniJS main function
// in the active OmniOutliner document )
// omniJS code to evaluate in active document.
const omniJS = () => {
const main = () => {
const styleProperties = {
FontCondensed: false,
FontFamily: 'Helvetica Neue',
FontFillColor: Color.white,
FontFixedPitch: false,
FontItalic: true,
FontName: 'Helvetica Neue Medium Italic',
FontNarrow: false,
FontSize: 28,
FontStrokeColor: Color.red,
FontStrokeWidth: 2,
FontWeight: 6
};
document.editors[0].selectedNodes.forEach(
node => setStyleProperties(styleProperties)(
node.object.style
)
);
};
// GENERAL AND RE-USABLE HELPER FUNCTION
const setStyleProperties = dictKeyValues => styleObject => {
Object.keys(dictKeyValues)
.forEach(
k => styleObject.set(
Style.Attribute[k],
dictKeyValues[k]
)
)
};
// MAIN FUNCTION CALLED HERE.
return main();
};
// JAVASCRIPT FOR AUTOMATION TO LAUNCH OMNI JS
// (evaluate this whole file in Script Editor with language tab
// at top left set to JavaScript)
// outlineOmniJSWithArgs :: Function -> [...OptionalArgs] -> a
function outlineOmniJSWithArgs(f) {
return Application('omniOutliner')
.evaluateJavascript(
`(${f})(${Array.from(arguments)
.slice(1).map(JSON.stringify)})`
);
};
return 0 < Application('OmniOutliner').documents.length ? (
outlineOmniJSWithArgs(omniJS)
) : 'No documents open in OmniOutliner.'
})();