jxa
Access OS X JavaScript for Automation APIs directly in node
Similar to the 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. The only difference is that you must get a handle to the Application
object by requiring this module.
var Application = Application; var iTunes = ; var name = iTunescurrentTrackname;var artist = iTunescurrentTrack; console;// Pay No Mind (feat. Passion Pit) by Madeon iTunes;// Music pauses iTunes;// 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)'
>