【发布时间】:2016-04-02 23:26:27
【问题描述】:
我正在使用 OS X JavaScript for Automation (JXA),我希望能够捕获“开放位置”Apple 事件。
根据 http://www.macosxautomation.com/applescript/linktrigger/,我设置了一个客户 URL 处理程序。我该怎么做相当于
on open location this_URL
...
end open location
与 JXA?我尝试了以下所有方法,但都无法执行:
app = Application.currentApplication();
app.includeStandardAdditions = true;
function run() {
app.displayDialog(JSON.stringify(arguments));
}
function openLocation() {
app.displayDialog(JSON.stringify(arguments));
}
function openDocuments() {
app.displayDialog(JSON.stringify(arguments));
}
function onOpenLocation() {
app.displayDialog(JSON.stringify(arguments));
}
Apple 的 JXA 文档 (https://developer.apple.com/library/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/OSX10-10.html#//apple_ref/doc/uid/TP40014508-CH109-SW15) 没有讨论如何处理打开位置事件。我的脚本会被打开,因为如果我将它添加到函数之外,我会得到一个显示的警报。我只是无法让函数执行并在 URL 中传递。
我正在通过一个 AppleScript 处理程序来解决这个问题,该处理程序随后会调用我的 JXA 代码,但这肯定不太理想。
我也没有在 JXA Cookbook (https://github.com/dtinth/JXA-Cookbook) 中看到任何关于此的内容。
【问题讨论】:
-
好问题。期待答案。
-
函数签名中的参数遗漏是复制粘贴错误吗?因为它应该是
function openLocation(thisURL) { // process thisURL }如果它打算工作...... -
@kopischke:不,我故意省略了 URL 参数(例如,thisURL)。我正在使用 JS 函数可用的特殊“参数”来确定我的函数是否被调用。我相信我按照您的建议使用显式参数进行了尝试,但这有关系吗?
标签: macos automation applescript javascript-automation