.runExtensionScript
A minimal example showing a slight puzzle with JS Object keys when passing arguments to, and returning values from, the very useful osascript method:
Application("Bike").runExtensionScript
A minimal example showing one key (but not all) replaced by a generic new key of the form k00n
(() => {
"use strict";
function run(argv) {
return Object.fromEntries(argv);
}
// main :: IO ()
const main = () =>
Application("Bike").runExtensionScript(
`${run}`,
{ options: [["Alpha", 9], ["Beta", 16]] }
);
return JSON.stringify(
main(),
null, 2
);
})();
Result:
{
"Beta": 16,
"k001": 9
}
Or taking a slightly different approach, we obtain an unexpected usrf key, and a flattening of the expected Array of pairs:
(() => {
"use strict";
function run(argv) {
return Object.entries(argv)
}
// main :: IO ()
const main = () =>
Application("Bike").runExtensionScript(
`${run}`,
{ options: { "Alpha": 9, "Beta": 16 } }
);
return JSON.stringify(
main(),
null, 2
);
})();
→
[
[
"usrf",
[
"Alpha",
9,
"Beta",
16
]
]
]
A third example may shed some light on the unexpected .usrf key:
(() => {
"use strict";
function run(argv) {
return argv.usrf
}
// main :: IO ()
const main = () =>
Application("Bike").runExtensionScript(
`${run}`,
{ options: { "Alpha": 9, "Beta": 16 } }
);
return JSON.stringify(
main(),
null, 2
);
})();
→
[
"Alpha",
9,
"Beta",
16
]