Skip to content

rbrtrbrt/node-osascript

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-osascript NPM version Build Status

Use AppleScript from node.js

Execute AppleScript from node.js and process the results.

Install

$ npm install node-osascript

Overview

Execute AppleScript and use the results of the javascript in node. The result is transformed into a javascript object using PEG.js So AppleScript lists are transformed into an Array, Records into a plain object and Dates to the Date type. Numbers, Booleans and Strings are converted, and null converts to null, and missing value to undefined.

Examples

Simple

var osascript = require('node-osascript');

osascript.execute('display dialog "What should I do?" buttons {"Go home", "Work", "Nothing"}\nset DlogResult to result\n return result', function(err, result, raw){
  if (err) return console.error(err)
  console.log(result, raw)
});

Injecting variables

You can inject a javascript object into the script to have acces to these variables.

var osascript = require('node-osascript');

osascript.execute('display dialog message', { message : "Hello from Node.JS" },function(err, result, raw){
  if (err) return console.error(err)
  console.log(result, raw)
});

API

Methods

execute(script, [variables], callback)

Execute the script, if specified injecting the variables into the AppleScript.

osascript.execute('script', { varName : 'value'}, function(err, result, raw){
  if (err) return console.error(err)
    console.log(result, raw)
});
executeFile(path, [variables], callback)

Execute file in path, if specified injecting the variables into the AppleScript.

osascript.executeFile('path/to/script.scpt', { varName : 'value'}, function(err, result, raw){
  if (err) return console.error(err)
    console.log(result, raw)
});

Tests

To run platform independent tests use:

npm test

If you are on macOS you can run all tests using:

npm testall

License

MIT

Changelog

2.0.0
1.0.4
  • Fix for breaking change in node 6 (See #7 Thanks to rosszurowski)
  • Update dependencies
1.0.3
  • When date cannot be parsed by Javascript, return original string value (See #5)
  • Added support for multiline strings and for unquoted strings in osascript output (See #5)
1.0.2
  • Unrecognized result is know always treated as a raw string. (Fix #3)
1.0.1
  • Fix a bug where empty results where considert an error (Fix #2)
1.0.0
  • Stable release
  • Fix package.json
0.0.1
  • Inital release

About

Use AppleScript from node

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 99.1%
  • AppleScript 0.9%