Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wtfaremyinitials/jxa
Access macOS JavaScript for Automation APIs directly in node
https://github.com/wtfaremyinitials/jxa
Last synced: 8 days ago
JSON representation
Access macOS JavaScript for Automation APIs directly in node
- Host: GitHub
- URL: https://github.com/wtfaremyinitials/jxa
- Owner: wtfaremyinitials
- Created: 2016-05-26T19:36:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-04-01T19:55:15.000Z (over 5 years ago)
- Last Synced: 2024-10-05T00:22:03.515Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 42 KB
- Stars: 307
- Watchers: 9
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
jxa
===![](https://img.shields.io/npm/dm/jxa.svg)
![](https://img.shields.io/npm/v/jxa.svg)
![](https://img.shields.io/npm/l/jxa.svg)> Access macOS JavaScript for Automation APIs directly in node
Similar to the [osa2](https://www.npmjs.com/package/osa2) module, but with synchronous calls and an API with a bit more 'magic'.
If you're building a library, use `osa2`. This module is best suited for small scripts.## Installation
**Module:** `npm install --save jxa`
**REPL:** `npm install -g jxa`
## Usage
Interact with apps in the same way you would with Apple's official JavaScript for automation runtime, as described [here](https://developer.apple.com/library/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/OSX10-10.html#//apple_ref/doc/uid/TP40014508-CH109-SW1). The only difference is that you must get a handle to the `Application` object by requiring this module.
```js
var Application = require('jxa').Application;var iTunes = Application('iTunes');
var name = iTunes.currentTrack.name();
var artist = iTunes.currentTrack.artist();console.log(name + ' by ' + artist);
// Pay No Mind (feat. Passion Pit) by MadeoniTunes.pause();
// Music pausesiTunes.play();
// Music plays
```If you install JXA globally (`npm install -g jxa`) a REPL is provided that exposes Application() in the global scope.
```
will@laptop ~ $ jxa-node
> Application('iTunes')
[object JXAReference => [object Application]]
> Application('iTunes').play()
undefined
> Application('iTunes').currentTrack
[object JXAReference => [object ObjectSpecifier]]
> Application('iTunes').currentTrack.name()
'No Problem (feat. Lil Wayne & 2 Chainz)'
>
```