gpt4 book ai didi

macos - 使用 OS X JavaScript for Automation (JXA) 监听 "open location"Apple 事件

转载 作者:行者123 更新时间:2023-12-02 01:21:27 24 4
gpt4 key购买 nike

我正在使用 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 ) 中也没有看到任何关于此的内容。

最佳答案

这个问题已经很老了,但对于任何现在或 future 的 Google 访问者来说,正确使用的函数名称是 GURLGURL (不,我不是在开玩笑)。您的函数签名应如下所示:

#!/usr/bin/env osascript -l JavaScript

function GURLGURL(url) {
const App = Application.currentApplication();
App.includeStandardAdditions = true;

App.doShellScript(`echo ${url} > ~/Downloads/url-arg.txt`);
return true;
}

我在阅读this archived developer document后发现了这一点,然后使用控制台应用程序探测我的 JXA 脚本的 applet 进程。分派(dispatch)的消息是 GURLGURL,如 get URL 中所示。

为 Apple 为最好的 AppleScript 版本策划最糟糕的开发者体验而干杯。

关于macos - 使用 OS X JavaScript for Automation (JXA) 监听 "open location"Apple 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34504937/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com