JXA source – evaluating code through .evaluateJavascript
(() => {
"use strict";
// A regression in OmniOutliner 5.8.3 causes a crash
// when a non-string value is returned from the
// .evaluateJavascript method.
// This code, evaluated from Script Editor, for example,
// crashes (on the return of a value) in OO 5.8.3,
// but works fine in OO 5.8.2
// This looks like a regression to a value return
// crasher which had been fixed in earlier builds.
// A JavaScript for Automation (JXA) script,
// for evaluation by OmniOutliner.evaluateJavascript(...)
// Adapted from test code helpfully submitted by
// @unlocked2412
const omnijsMain = () => {
const main = () =>
userDialog([
new Form.Field.String(
"keyString",
"Display",
"Default"
)
])(
"Hello World"
)(
// This causes a crash in OO 5.8.3
// but not in OO 5.82
// returns an object, rather than
// a string, to JXA.
x => x
// This is OK
// x => ""
);
// --------------------- GENERIC ---------------------
// FUNCTIONS --
// userDialog :: [Form.Field] ->
// String -> values -> () -> Promise
const userDialog = fields =>
// General constructor for omniJS dialogs,
// where f is a continuation function
// in which a dialog result
// is bound to the function argument.
prompt => f => fields.reduce(
(form, field) => (
form.addField(field),
form
),
// Seed value - a new black form.
new Form()
)
.show(prompt, "OK")
.then(f);
return main();
};
const oo = Application("OmniOutliner");
return (
oo.activate(),
oo.evaluateJavascript(
`(${omnijsMain})()`
)
);
})();