如何在JXA AppleScript中访问系统信息?

时间:2017-12-30 23:31:37

标签: javascript applescript jxa

在AppleScript中,您可以执行以下操作:

set username to short user name of (system info)
set computername to host name of (system info)
set ethernet to primary Ethernet address of (system info)
set ipaddress to IPv4 address of (system info)
set osver to system version of (system info)

我不确定如何访问系统信息对象。我如何在JXA(JavaScript AppleScript)中执行此操作? 谢谢!

1 个答案:

答案 0 :(得分:1)

我在AppleScript中使用的JavaScript非常少,主要是使用网页来获取和设置信息,但是我可以告诉您有关用于JavaScript的AppleScript system info命令以及您已经显示的代码。< / p>

AppleScript system info命令是标准添加的一部分,可以使用脚本编辑器中的以下示例JavaScript代码进行访问。

app = Application.currentApplication();
app.includeStandardAdditions = true;

var username        =   app.systemInfo().shortUserName;
var computername    =   app.systemInfo().hostName;
var ethernet        =   app.systemInfo().primaryEthernetAddress;
var ipaddress       =   app.systemInfo().ipv4Address;
var osver           =   app.systemInfo().systemVersion;

在脚本编辑器的库中查看标准版AppleScript字典。