{"id":13671090,"url":"https://github.com/mikaelbr/node-osascript","last_synced_at":"2025-03-16T21:30:45.281Z","repository":{"id":20909914,"uuid":"24197699","full_name":"mikaelbr/node-osascript","owner":"mikaelbr","description":"A stream for Apple Open Scripting Architecture (OSA) through AppleScript or Javascript","archived":false,"fork":false,"pushed_at":"2015-11-26T00:39:55.000Z","size":23,"stargazers_count":54,"open_issues_count":5,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-09T01:49:39.167Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mikaelbr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-18T17:20:54.000Z","updated_at":"2024-09-14T13:48:13.000Z","dependencies_parsed_at":"2022-08-26T18:50:59.591Z","dependency_job_id":null,"html_url":"https://github.com/mikaelbr/node-osascript","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikaelbr%2Fnode-osascript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikaelbr%2Fnode-osascript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikaelbr%2Fnode-osascript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikaelbr%2Fnode-osascript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikaelbr","download_url":"https://codeload.github.com/mikaelbr/node-osascript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243830937,"owners_count":20354853,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T09:00:58.706Z","updated_at":"2025-03-16T21:30:44.896Z","avatar_url":"https://github.com/mikaelbr.png","language":"JavaScript","readme":"osascript\n===\n\n\u003e Node.js module for doing Apple Open Scripting Architecture (OSA) in JavaScript or AppleScript.\n\n## Install\n```\nnpm install --save osascript\n```\n\n## Requirements\n\nFor using JavaScript as Automation language, Mac OS X Yosemite is required.\nOn versions before that, you can pass AppleScripts.\n\n## Usage\n\nBy default, if no other type is defined and the passed file is not a AppleScript\nfile (with extensions `.scpt` or `.applescript`), JavaScript is used.\n\nSee the last example for overriding this behaviour and passing on AppleScript\ninstead. All API's are the same.\n\n### Default stream\n\n```javascript\nvar osascript = require('osascript');\nvar fs = require('fs');\n\n// Run JavaScript file through OSA\nfs.createReadStream('someFile.js')\n  .pipe(osascript())\n  .pipe(process.stdout);\n```\n\nThis will pipe the data from `someFile.js` to the Apple Open Scripting Architecture (OSA)\nand print the result to the standard output.\n\nYou can also do this in a short-hand:\n\n```javascript\n// note the file method after require ¬\nvar osascript = require('osascript').file;\n\n// Run JavaScript file through OSA\nosascript('someFile.js').pipe(process.stdout);\n```\n\nOr if you only have a string, you can do that as well\n```javascript\n// note the eval method after require ¬\nvar osascript = require('osascript').eval;\n\n// Run JavaScript text through OSA\nosascript('console.log(\"Hello, world!\");').pipe(process.stdout);\n```\n\n### Using a callback\n\nIf you don't want to use a stream (just get the buffered output)\nyou can do this on the `file` and `eval` methods by passing a\nfunction as the last argument:\n\n```javascript\n// note the file method after require ¬\nvar osascript = require('osascript').file;\n\n// Run JavaScript file through OSA\nosascript('someFile.js', function (err, data) {\n  console.log(err, data);\n});\n```\n\n```javascript\n// note the eval method after require ¬\nvar osascript = require('osascript').eval;\n\n// Run JavaScript text through OSA\nosascript('console.log(\"Hello, world!\");', function (err, data) {\n  console.log(err, data);\n});\n```\n\n### Using AppleScript\n\nAs JavaScript as OSA isn't working on versions before Yosemite,\nwe can use AppleScript as well. JavaScript is the default\nto try to encourage JS instead of AppleScript. When\na filename is passed, AppleScript will be used if the filename\nhas an AppleScript extension (`.scpt` or `.applescript`).\n\n\n```javascript\nvar osascript = require('osascript');\nvar fs = require('fs');\n\n// Run JavaScript file through OSA\nfs.createReadStream('someAppleScript.applescript')\n  // Need to override options to define AppleScript\n  .pipe(osascript({ type: 'AppleScript' }))\n  .pipe(process.stdout);\n```\n\n```javascript\n// note the file method after require ¬\nvar osascript = require('osascript').file;\n\n// No need to pass options, as it can be deduced from filename.\nosascript('someFile.applescript', function (err, data) {\n  console.log(err, data);\n});\n```\n\nSee [more examples](./examples).\n\n### API\n\nAPI from base function required in this way:\n\n```javascript\nvar osascript = require('osascript');\n```\n\nAll endpoints uses `options`:\n\n```javascript\nvar defaultOptions = {\n  type: 'JavaScript',\n  args: [] // List of string arguments\n};\n```\n\nType is passed as language (option `-l`) to `osascript`.\nCan be either `JavaScript` (in Yosemite) or `AppleScript`.\n\n`flags` can be used to change the output style of return values from functions executed by osascript:\n\n```js\n// JSON parsable return\nosascript('(function(){return [\"foo\",5, {foo: \"barz\"}]})()', {flags: ['-s', 's']}, function (data) {\n  console.log(data); // [\"foo\", 5, {\"foo\":\"barz\"}]\n});\n```\n\n`args` is a list of strings passed in as arguments to your scripts. In JavaScript\nyou can access them using:\n\n```js\nObjC.import('Cocoa');\nvar args = ObjC.deepUnwrap($.NSProcessInfo.processInfo.arguments).slice(4);\n```\n\n`.slice(4)` is to cut away program name and language argument. In addition,\n`node-osascript` has to put in a `-` to indicate that the following list of\nstrings should be passed as arguments.  This `-` is on index 3.\n\n#### `osascript([options: Object])`\n\nCreates a PassThrough stream that can get piped text manually\n(text or files).\n\n#### `osascript.file(file[, options: Object, callback:function (err, data)])`\nSee `options` as defined above.\n\nIf callback function is passed, the buffered output from\nthe OSA is passed as data (initiates the data immediately)\n\n#### `osascript.eval(scriptText[, options: Object, callback:function (err, data)])`\n`scriptText` is script in the language type as defined.\n\nSee `options` as defined above.\n\nIf callback function is passed, the buffered output from\nthe OSA is passed as data (initiates the data immediately)\n\n## TODO\n\n* [ ] Tests\n* [x] Error handling\n\n## License\n\n[MIT License](LICENSE)\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikaelbr%2Fnode-osascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikaelbr%2Fnode-osascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikaelbr%2Fnode-osascript/lists"}