jxa

直接在 node 中访问用于自动化 API 的 macOS JavaScript。「Access macOS JavaScript for Automation APIs directly in node」

  • Owner: wtfaremyinitials/jxa
  • Platform: Linux, Mac, Windows
  • License::
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

jxa

直接在 Node 中访问 macOS JavaScript for Automation API

osa2 模块类似,但具有同步调用和更多'魔术'的API。 如果您正在构建库,请使用 osa2 。这个模块最适合小脚本。

安装

模块: npm install --save jxa

REPL: npm install -g jxa

用法

与 Apple 官方的自动化运行时 JavaScript 进行交互的方式与这里描述的相同,唯一的区别是,您必须通过要求此模块来获取 Application 对象的句柄。

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

如果您全局安装 JXA( npm install -g jxa ),则会提供一个 REPL 来将 Application() 公开在全局范围内。

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)'
>

Main metrics

Overview
Name With Ownerwtfaremyinitials/jxa
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 1)
PlatformLinux, Mac, Windows
License:
所有者活动
Created At2016-05-26 19:36:34
Pushed At2019-04-01 19:55:15
Last Commit At2017-04-23 15:41:59
Release Count0
用户参与
Stargazers Count306
Watchers Count9
Fork Count10
Commits Count34
Has Issues Enabled
Issues Count2
Issue Open Count1
Pull Requests Count0
Pull Requests Open Count1
Pull Requests Close Count2
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

jxa



Access macOS 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 = 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)'
>