我正在使用OS X JavaScript for Automation(JXA),我希望能够捕获"开放位置"的Apple Event.
根据http://www.macosxautomation.com/applescript/linktrigger/,我设置了一个客户URL处理程序.我该怎么做相同的
on open location this_URL
...
end open location
Run Code Online (Sandbox Code Playgroud)
与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));
}
Run Code Online (Sandbox Code Playgroud)
Apple的JXA文档(https://developer.apple.com/library/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/OSX10-10.html#//apple_ref/doc/uid/TP40014508-CH109-SW15)don '讨论如何处理开放位置事件.我的脚本将被打开,因为如果我将其添加到函数之外,我可以显示警告.我只是无法获得一个函数来执行并在URL中传递.
我正在通过使用AppleScript处理程序来解决这个问题,然后调用我的JXA代码,但这肯定不太理想.
我也没有在JXA Cookbook(https://github.com/dtinth/JXA-Cookbook)中看到任何相关内容.
当我使用AppleScript获取对象的属性时,将返回一条记录.
tell application "iPhoto"
properties of album 1
end tell
==> {id:6.442450942E+9, url:"", name:"Events", class:album, type:smart album, parent:missing value, children:{}}
Run Code Online (Sandbox Code Playgroud)
如何迭代返回记录的键/值对,以便我不必确切地知道记录中的键是什么?
为了澄清这个问题,我需要枚举键和值,因为我想编写一个通用的AppleScript例程来将记录和列表转换为JSON,然后由脚本输出.
当Safari未运行时,我可以通过以下Automation JavaScript代码打开Safari.
safari = Application('Safari')
Run Code Online (Sandbox Code Playgroud)
但是当Safari运行并且没有窗口时,上面的代码不会打开Safari的新窗口.
我试着添加以下代码.
window = safari.Window()
safari.windows.push(window)
Run Code Online (Sandbox Code Playgroud)
但没有影响.
当Safari正在运行但没有窗口时,如何通过JavaScript自动化打开Safari的新窗口?
目前,我使用以下代码
safari = Application('Safari')
safari.open(Path('~/dummy'))
Run Code Online (Sandbox Code Playgroud)
我不喜欢它.