Code Monkey home page Code Monkey logo

node-osascript's Introduction

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

node-osascript's People

Contributors

fweinb avatar leonid-shevtsov avatar rbrtrbrt avatar rosszurowski avatar slattery avatar zeke avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.