Run JXA code and get result.
Install with npm:
npm install @jxa/run
Requirement:
- macOS 10.10 or later.
export declare function run<R>(jxaCodeFunction: (...args: any[]) => void, ...args: any[]): Promise<R>
Illustration of usage
const resultPromise = run(JSXFn, argumentsOfJSXFn);
JSXFn
: This function is run as JXA.- 📝 This
JSXFn
is serialized(toString
) and pass to JXA environment. - Warning The function cannot close over variables in a parent's scope.
- You need to pass arguments as
argumentsOfJSXFn
explicitly
- 📝 This
argumentsOfJSXFn
: An arguments ofJSXFn
OK:
// OK
(async () => {
// `name` is "nodejs"
const result = await run(name => {
return "Hello there, " + name + "!"
}, "nodejs");
assert.strictEqual(result, "Hello there, nodejs!");
})();
NG:
// NG
(async () => {
const name = "nodejs"
const result = await run(name => {
return "Hello there, " + name + "!"; // can not access to `name` from JXA enviroment
});
assert.strictEqual(result, "Hello there, nodejs!");
})();
(async () => {
const result = await run(
// run this function as JXA code
() => {
return Application("System Events")
.currentUser()
.name()
}
);
assert.strictEqual(result, process.env.USER);
})();
See Releases page.
yarn test
Pull requests and stars are always welcome.
For bugs and feature requests, please create an issue.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
- wtfaremyinitials/osa2: Interact with Apple's Open Scripting Architecture in node.js
- sindresorhus/run-jxa: Run JXA code and get the result
MIT © azu