我正在使用OS X JavaScript的自动化(JXA),我希望能够捕捉到“开放位置”苹果事件。
根据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));
}
苹果的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 )中也没有看到任何关于这方面的内容。
发布于 2016-04-27 00:06:51
正如您所建议的,(目前)诀窍似乎是将控制权立即传递给同一捆绑包中的第二个(用于自动化的JavaScript)脚本。
on open location strURL
run script (path to resource "jsHandler.scpt" in directory "Scripts") with parameters {{|URL|:strURL}}
end open location
https://stackoverflow.com/questions/34504937
复制