# node-osascript

> Execute AppleScript from Node

Latest version **2.1.0** (published 2018-08-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-osascript
pnpm add node-osascript
yarn add node-osascript
bun add node-osascript
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2018-08-27 |
| First published | 2014-06-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 56.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 68 |
| Author | Fabrice Weinberg |
| Maintainers | fweinb |
| Keywords | apple, script, applescript, osascript |

## Links

- npm: https://www.npmjs.com/package/node-osascript
- Repository: https://github.com/FWeinb/node-osascript
- Homepage: https://github.com/FWeinb/node-osascript#readme
- Issues: https://github.com/FWeinb/node-osascript/issues
- npm.io page: https://npm.io/package/node-osascript

## Dependencies (1)

- [buffers](https://npm.io/package/buffers.md) ^0.1.1

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 2.1.0 (latest) — 2018-08-27
- 2.0.0 — 2017-02-17
- 1.0.4 — 2016-05-11
- 1.0.2 — 2014-11-29
- 1.0.1 — 2014-11-21
- 1.0.0 — 2014-09-09
- 0.0.1 — 2014-06-08

## README

# node-osascript [![NPM version](https://badge.fury.io/js/node-osascript.svg)](http://badge.fury.io/js/node-osascript) [![Build Status](https://travis-ci.org/FWeinb/node-osascript.svg?branch=master)](https://travis-ci.org/FWeinb/node-osascript)

> Use AppleScript from node.js

Execute AppleScript from node.js and process the results.

<details>
  <summary><b>Table of Contents</b></summary>

- [Install](#install)
- [Overview](#overview)
- [Examples](#examples)
  - [Simple](#simple)
  - [Injecting Variables](#injecting-variables)
  - [Timeout](#timeout)
- [API](#api)
- [Tests](#tests)
- [License](#license)
- [Changelog](#changelog)

</details>

## Install

```sh
$ 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 as well as `Numbers`, `Booleans` and `Strings`.

## Examples

### Simple

```js
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.

```js
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)
});
```

### Timeout

You can force an AppleScript to stop running

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

  var childProcess = 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)
  });

  //after 20 seconds, the AppleScript will be killed
  setTimeout(function(){
    console.log('kill');
    childProcess.stdin.pause();
    childProcess.kill();
  },20000)

```


## API

### Methods

#### `execute(script, [variables], callback)`

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

```js
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.

```js
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

---
_Source: https://npm.io/package/node-osascript · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
