神刀安全网

jxa: Access OS X JavaScript for Automation APIs Directly in Node.js

jxa

jxa: Access OS X JavaScript for Automation APIs Directly in Node.js jxa: Access OS X JavaScript for Automation APIs Directly in Node.js jxa: Access OS X JavaScript for Automation APIs Directly in Node.js

Access OS X JavaScript for Automation APIs directly in node

Similar to the osa module, but with a slightly easier API. If you’re building a library, the osa module is better suited as its calls are not synchronous.

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 = 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 Madeon  iTunes.pause(); // Music pauses  iTunes.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)' > 

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » jxa: Access OS X JavaScript for Automation APIs Directly in Node.js

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址