{"_id":"run-jxa","_rev":"4320855","name":"run-jxa","description":"Run JXAcode and get the result","dist-tags":{"latest":"4.0.0"},"maintainers":[{"name":"sindresorhus","email":""}],"time":{"modified":"2026-04-07T22:31:36.000Z","created":"2016-11-14T10:10:52.413Z","4.0.0":"2025-09-09T16:16:04.142Z","3.0.0":"2021-08-12T14:32:03.800Z","2.0.0":"2019-04-06T11:49:20.387Z","1.2.0":"2017-12-06T11:40:07.717Z","1.1.0":"2017-03-16T06:54:38.219Z","1.0.2":"2017-02-05T10:31:48.743Z","1.0.1":"2017-02-03T17:15:27.181Z","1.0.0":"2016-11-14T10:10:52.413Z"},"users":{},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/run-jxa.git"},"versions":{"4.0.0":{"name":"run-jxa","version":"4.0.0","description":"Run JXAcode and get the result","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/run-jxa.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=20"},"scripts":{"test":"xo && ava && tsd"},"keywords":["macos","jxa","javascript","osascript","run","mac","execute","code","script","automation"],"dependencies":{"execa":"^9.6.0","macos-version":"^6.0.0","subsume":"^4.0.0","type-fest":"^4.41.0"},"devDependencies":{"ava":"^6.4.1","tsd":"^0.33.0","xo":"^1.2.2"},"_id":"run-jxa@4.0.0","gitHead":"28cf9f362cbf44651a938d350e58fbe087df9014","types":"./index.d.ts","bugs":{"url":"https://github.com/sindresorhus/run-jxa/issues"},"homepage":"https://github.com/sindresorhus/run-jxa#readme","_nodeVersion":"20.19.1","_npmVersion":"10.9.2","dist":{"shasum":"e2afd65e30cfbaac7a76c5901d96c4c83fd4e2a8","size":3289,"noattachment":false,"key":"/run-jxa/-/run-jxa-4.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/run-jxa/download/run-jxa-4.0.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/run-jxa_4.0.0_1757434563944_0.1983759503803575"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-09-09T16:16:04.142Z","publish_time":1757434564142,"_source_registry_name":"default","_cnpm_publish_time":1757434564142},"3.0.0":{"name":"run-jxa","version":"3.0.0","description":"Run JXAcode and get the result","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/run-jxa.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","engines":{"node":"^12.20.0 || ^14.13.1 || >=16.0.0"},"scripts":{"test":"xo && ava && tsd"},"keywords":["macos","jxa","javascript","osascript","run","mac","execute","code","script","automation"],"dependencies":{"execa":"^5.1.1","macos-version":"^6.0.0","subsume":"^4.0.0","type-fest":"^2.0.0"},"devDependencies":{"ava":"^3.15.0","tsd":"^0.17.0","xo":"^0.44.0"},"gitHead":"964cb11b485d30cd51023cc3d18d7061842ff1fa","bugs":{"url":"https://github.com/sindresorhus/run-jxa/issues"},"homepage":"https://github.com/sindresorhus/run-jxa#readme","_id":"run-jxa@3.0.0","_nodeVersion":"12.22.1","_npmVersion":"7.10.0","dist":{"shasum":"7d7a0fb183cef4b7132237bcfeb58cb705aecbfc","size":2781,"noattachment":false,"key":"/run-jxa/-/run-jxa-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/run-jxa/download/run-jxa-3.0.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/run-jxa_3.0.0_1628778723649_0.7715859071572626"},"_hasShrinkwrap":false,"publish_time":1628778723800,"_cnpm_publish_time":1628778723800,"_cnpmcore_publish_time":"2021-12-17T13:20:12.914Z"},"2.0.0":{"name":"run-jxa","version":"2.0.0","description":"Run JXAcode and get the result","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/run-jxa.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd"},"keywords":["macos","jxa","javascript","osascript","run","mac","execute","code","script","automation"],"dependencies":{"execa":"^1.0.0","macos-version":"^5.2.0","subsume":"^2.1.0","type-fest":"^0.3.0"},"devDependencies":{"ava":"^1.4.1","tsd":"^0.7.2","xo":"^0.24.0"},"gitHead":"b69a2d47eb1a3622d8803b743a0c00aef982a4c1","bugs":{"url":"https://github.com/sindresorhus/run-jxa/issues"},"homepage":"https://github.com/sindresorhus/run-jxa#readme","_id":"run-jxa@2.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.15.1","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"1634ba52f0d2e58ffc19673f41c4b63259ee2ec7","size":2873,"noattachment":false,"key":"/run-jxa/-/run-jxa-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/run-jxa/download/run-jxa-2.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/run-jxa_2.0.0_1554551360212_0.31969291320852933"},"_hasShrinkwrap":false,"publish_time":1554551360387,"_cnpm_publish_time":1554551360387,"_cnpmcore_publish_time":"2021-12-17T13:20:13.225Z"},"1.2.0":{"name":"run-jxa","version":"1.2.0","description":"Run JXAcode and get the result","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/run-jxa.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["macos","jxa","javascript","osascript","run","mac","execute","code","script","automation"],"dependencies":{"execa":"^0.8.0","macos-version":"^4.0.0","subsume":"^1.0.0"},"devDependencies":{"ava":"*","xo":"*"},"gitHead":"7f8e76abc4f8fec45c60889444b2ba2f4cdddc1c","bugs":{"url":"https://github.com/sindresorhus/run-jxa/issues"},"homepage":"https://github.com/sindresorhus/run-jxa#readme","_id":"run-jxa@1.2.0","_shasum":"41062a4cdcdb32cebd00a28af03acc7299d50cf0","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.11.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"41062a4cdcdb32cebd00a28af03acc7299d50cf0","size":2544,"noattachment":false,"key":"/run-jxa/-/run-jxa-1.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/run-jxa/download/run-jxa-1.2.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/run-jxa-1.2.0.tgz_1512560406820_0.8206248201895505"},"directories":{},"publish_time":1512560407717,"_hasShrinkwrap":false,"_cnpm_publish_time":1512560407717,"_cnpmcore_publish_time":"2021-12-17T13:20:13.448Z"},"1.1.0":{"name":"run-jxa","version":"1.1.0","description":"Run JXA (macOS JavaScript for Automation) code and get the result","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/run-jxa.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["macos","osx","mac","jxa","javascript","osascript","run","execute","code","script","automation"],"dependencies":{"execa":"^0.5.0","macos-version":"^4.0.0","subsume":"^1.0.0"},"devDependencies":{"ava":"*","xo":"*"},"xo":{"esnext":true},"gitHead":"2b7717a4f5063f12d49ff2d386c47904012d2e88","bugs":{"url":"https://github.com/sindresorhus/run-jxa/issues"},"homepage":"https://github.com/sindresorhus/run-jxa#readme","_id":"run-jxa@1.1.0","_shasum":"325c023ce3a8c754b8314c7e6fd35ead186c8846","_from":".","_npmVersion":"2.15.11","_nodeVersion":"4.7.3","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"325c023ce3a8c754b8314c7e6fd35ead186c8846","size":2521,"noattachment":false,"key":"/run-jxa/-/run-jxa-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/run-jxa/download/run-jxa-1.1.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/run-jxa-1.1.0.tgz_1489647277975_0.45538952155038714"},"directories":{},"publish_time":1489647278219,"_hasShrinkwrap":false,"_cnpm_publish_time":1489647278219,"_cnpmcore_publish_time":"2021-12-17T13:20:13.684Z"},"1.0.2":{"name":"run-jxa","version":"1.0.2","description":"Run JXA (macOS JavaScript for Automation) code and get the result","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/run-jxa.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["macos","osx","mac","jxa","javascript","osascript","run","execute","code","script","automation"],"dependencies":{"execa":"^0.5.0","subsume":"^1.0.0"},"devDependencies":{"ava":"*","xo":"*"},"xo":{"esnext":true},"gitHead":"feb306e9c7d1d654ba4a7739d4c465d637e74488","bugs":{"url":"https://github.com/sindresorhus/run-jxa/issues"},"homepage":"https://github.com/sindresorhus/run-jxa#readme","_id":"run-jxa@1.0.2","_shasum":"e0b30e97807e082c83137c7770e1d13c4837b5fe","_from":".","_npmVersion":"3.10.8","_nodeVersion":"6.9.1","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"e0b30e97807e082c83137c7770e1d13c4837b5fe","size":2573,"noattachment":false,"key":"/run-jxa/-/run-jxa-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/run-jxa/download/run-jxa-1.0.2.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/run-jxa-1.0.2.tgz_1486290706971_0.14423423213884234"},"directories":{},"publish_time":1486290708743,"_hasShrinkwrap":false,"_cnpm_publish_time":1486290708743,"_cnpmcore_publish_time":"2021-12-17T13:20:13.905Z"},"1.0.1":{"name":"run-jxa","version":"1.0.1","description":"Run JXA (macOS JavaScript for Automation) code and get the result","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/run-jxa.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["macos","osx","mac","jxa","javascript","osascript","run","execute","code","script","automation"],"dependencies":{"execa":"^0.5.0","subsume":"^1.0.0"},"devDependencies":{"ava":"*","xo":"*"},"xo":{"esnext":true},"gitHead":"7230fc41cacc656f3e4336c2bda69588867fae74","bugs":{"url":"https://github.com/sindresorhus/run-jxa/issues"},"homepage":"https://github.com/sindresorhus/run-jxa#readme","_id":"run-jxa@1.0.1","_shasum":"39655e599a2e3353b1d85507ec18feecd30b81b4","_from":".","_npmVersion":"2.15.11","_nodeVersion":"4.6.2","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"39655e599a2e3353b1d85507ec18feecd30b81b4","size":2578,"noattachment":false,"key":"/run-jxa/-/run-jxa-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/run-jxa/download/run-jxa-1.0.1.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/run-jxa-1.0.1.tgz_1486142125079_0.12228677002713084"},"directories":{},"publish_time":1486142127181,"_hasShrinkwrap":false,"_cnpm_publish_time":1486142127181,"_cnpmcore_publish_time":"2021-12-17T13:20:14.178Z"},"1.0.0":{"name":"run-jxa","version":"1.0.0","description":"Run JXA (macOS JavaScript for Automation) code and get the result","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/run-jxa.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["macos","osx","mac","jxa","javascript","osascript","run","execute","code","script","automation"],"dependencies":{"execa":"^0.5.0","subsume":"^1.0.0"},"devDependencies":{"ava":"*","xo":"*"},"xo":{"esnext":true},"gitHead":"db67bc947edc02ab29cd14fb0dd096b81e8eec30","bugs":{"url":"https://github.com/sindresorhus/run-jxa/issues"},"homepage":"https://github.com/sindresorhus/run-jxa#readme","_id":"run-jxa@1.0.0","_shasum":"bbfc1b6d10547ebfc2e9c28521b8915fd6b06df3","_from":".","_npmVersion":"2.15.9","_nodeVersion":"4.6.1","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"bbfc1b6d10547ebfc2e9c28521b8915fd6b06df3","size":2547,"noattachment":false,"key":"/run-jxa/-/run-jxa-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/run-jxa/download/run-jxa-1.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/run-jxa-1.0.0.tgz_1479118252206_0.05102367792278528"},"directories":{},"publish_time":1479118252413,"_hasShrinkwrap":false,"_cnpm_publish_time":1479118252413,"_cnpmcore_publish_time":"2021-12-17T13:20:14.378Z"}},"readme":"# run-jxa\n\n> Run [JXA](https://github.com/dtinth/JXA-Cookbook) code and get the result\n\n*JXA is JavaScript for Automation on macOS. Requires macOS 10.10 or later.*\n\n## Install\n\n```sh\nnpm install run-jxa\n```\n\n## Usage\n\nUse a function:\n\n```js\nimport {runJxa} from 'run-jxa';\n\nconst result = await runJxa((unicorn, horse) => {\n\t// This is run in the JXA engine\n\treturn `I love ${unicorn} & ${horse}`;\n}, ['????', '????']);\n\nconsole.log(result);\n//=> 'I love ???? & ????'\n```\n\nOr a string:\n\n```js\nimport {runJxa} from 'run-jxa';\n\nconst result = await runJxa(`\n\tconst [unicorn, horse] = args;\n\treturn \\`I love \\${unicorn} & \\${horse}\\`;\n`, ['????', '????']);\n\nconsole.log(result);\n//=> 'I love ???? & ????'\n```\n\nCancel a long-running script:\n\n```js\nimport {runJxa} from 'run-jxa';\n\nconst controller = new AbortController();\n\n// Cancel after 5 seconds\nsetTimeout(() => {\n\tcontroller.abort();\n}, 5000);\n\ntry {\n\tconst result = await runJxa(() => {\n\t\t// Some potentially long-running operation\n\t\tconst app = Application('Finder');\n\t\treturn app.windows.length;\n\t}, undefined, {signal: controller.signal});\n\t\n\tconsole.log(result);\n} catch (error) {\n\tif (error.name === 'AbortError') {\n\t\tconsole.log('Script was cancelled');\n\t}\n}\n```\n\n## API\n\n### runJxa(input, arguments?, options?)\n\nReturns a `Promise` for the value returned from `input`.\n\n### runJxaSync(input, arguments?)\n\nReturns the value returned from `input`.\n\n#### input\n\nType: `Function | string`\n\nIf a function, it's stringified and passed to JXA. It should be [pure](https://en.wikipedia.org/wiki/Pure_function), meaning it doesn't access anything outside its body.\n\nIf a string, you can access the specified arguments with `args` array. Use the `arguments` parameter rather than template interpolation so you don't have to do escaping.\n\nYou can `console.log` inside `input`. It will be forwarded to stdout. Useful for debugging.\n\nNote: The JXA context is completely synchronous, so asynchronous functions like `setTimeout` are not available.\n\n#### arguments\n\nType: `unknown[]`\n\nArguments to pass to the JXA context.\n\nItems should be serializable (`JSON.stringify`'able).\n\n#### options\n\nType: `object`\n\n##### signal\n\nType: `AbortSignal`\n\nAn [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) that can be used to cancel the JXA execution.\n\nOnly supported by the async `runJxa()` function, not the sync version.\n\n## Related\n\n- [is-jxa](https://github.com/sindresorhus/is-jxa) - Check if your code is running in a JXA environment\n","_attachments":{},"homepage":"https://github.com/sindresorhus/run-jxa#readme","bugs":{"url":"https://github.com/sindresorhus/run-jxa/issues"},"license":"MIT"}