1 | node-applescript
|
2 | ================
|
3 |
|
4 | A high-level way to execute AppleScript code through NodeJS, and retrieve
|
5 | the result as a native JavaScript object. Underneath the hood, this
|
6 | module is just a simple wrapper around the OS X `osascript` command.
|
7 |
|
8 | ### Why?
|
9 | AppleScripts are the only way to communicate and interact with certain
|
10 | external OS X processes, for example [iTunes](http://www.itunes.com).
|
11 |
|
12 | Easy Install
|
13 | ------------
|
14 |
|
15 | ``` bash
|
16 | $ npm install applescript
|
17 | ```
|
18 |
|
19 | Requirements
|
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 |
|
25 | Usage
|
26 | -----
|
27 |
|
28 | The `node-applescript` module provides `execString` and `execFile` functions
|
29 | to easily execute AppleScript commands and buffer the output into a calback.
|
30 |
|
31 | ``` js
|
32 | var 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.
|
36 | var script = 'tell application "iTunes" to get name of selection';
|
37 |
|
38 | applescript.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
|
52 | may pass an optional Array of String arguments to send to the applescript file.
|
53 |
|
54 | Licence
|
55 | -------
|
56 |
|
57 | The `node-applescript` module is licensed under the MIT license, of course!
|