UNPKG

1.61 kBMarkdownView Raw
1node-applescript
2================
3
4A high-level way to execute AppleScript code through NodeJS, and retrieve
5the result as a native JavaScript object. Underneath the hood, this
6module is just a simple wrapper around the OS X `osascript` command.
7
8### Why?
9AppleScripts are the only way to communicate and interact with certain
10external OS X processes, for example [iTunes](http://www.itunes.com).
11
12Easy Install
13------------
14
15``` bash
16$ npm install applescript
17```
18
19Requirements
20------------
21
22 * Mac (or Hackintosh) running [OS X](http://www.apple.com/macosx) (tested with Snow Leopard)
23 * [NodeJS](http://nodejs.org) (v0.2.0 or newer)
24
25Usage
26-----
27
28The `node-applescript` module provides `execString` and `execFile` functions
29to easily execute AppleScript commands and buffer the output into a calback.
30
31``` js
32var applescript = require('applescript');
33
34// Very basic AppleScript command. Returns the song name of each
35// currently selected track in iTunes as an 'Array' of 'String's.
36var script = 'tell application "iTunes" to get name of selection';
37
38applescript.execString(script, function(err, rtn) {
39 if (err) {
40 // Something went wrong!
41 }
42 if (Array.isArray(rtn)) {
43 rtn.forEach(function(songName) {
44 console.log(songName);
45 });
46 }
47});
48```
49
50`execFile` works the exact same way, except you pass the _path_ of the AppleScript
51(`*.applescript`) file as the first argument instead of the command itself, and you
52may pass an optional Array of String arguments to send to the applescript file.
53
54Licence
55-------
56
57The `node-applescript` module is licensed under the MIT license, of course!