Applescript中的Javascript

Applescript中的Javascript,javascript,applescript,Javascript,Applescript,我正试图在AppleScrip中运行一点Javascript,但毫无乐趣,也找不到问题所在 如果我在Chrome中从控制台运行Javascript,它工作得很好,但是当我将它插入到AppleScript中时,它什么也做不了 这是我的密码: set alertReply to display alert "New Build" message "A new build is now available!" buttons ["Cancel", "Show"] default button 2 gi

我正试图在AppleScrip中运行一点Javascript,但毫无乐趣,也找不到问题所在

如果我在Chrome中从控制台运行Javascript,它工作得很好,但是当我将它插入到AppleScript中时,它什么也做不了

这是我的密码:

set alertReply to display alert "New Build" message "A new build is now available!" buttons ["Cancel", "Show"] default button 2 giving up after 5
if button returned of alertReply is equal to "Show" then
tell application "Safari"
    activate
    tell window 1 
        set current tab to make new tab with properties {URL:"https://bamboo...."}
        delay 5
        do JavaScript "clickArtifactsAndWait(); function clickArtifactsAndWait () { var menu_items = document.getElementsByClassName('menu-item'); var id_prefix = 'artifacts:'; for (var i = 0, length = menu_items.length; i < length; i++) {   if (menu_items[i].children[0].id.substr(0, id_prefix.length) == id_prefix) {     menu_items[i].children[0].click();   } } setTimeout(downloadMacBuild, 3000);  }  function downloadMacBuild() { var links = document.getElementsByTagName('a') for (var i = 0, length = links.length; i < length; i++) {   if (links[i].innerHTML == 'builds-mac') {     links[i].click();   } }  }"

    end tell
end tell
end if
设置alertReply以显示警报“新建”消息“新版本现在可用!”按钮[“取消”,“显示”]默认按钮2 5后放弃
如果alertReply返回的按钮等于“显示”,则
告诉应用程序“Safari”
激活
告诉窗口1
设置当前选项卡以创建属性为{URL:]的新选项卡https://bamboo...."}
延迟5
执行JavaScript“clickArtifactsAndWait();函数clickArtifactsAndWait(){var menu_items=document.getElementsByClassName('menu-item');var id_prefix='artifacts:';for(var i=0,length=menu items.length;i
我必须使用Javascript,因为我试图单击并从中下载的链接是动态的,所以我不能只给applescript一个静态地址

我不知道,也许有更好的方法


非常感谢您的帮助!

AppleScript的
do javascript
命令在窗口上不执行任何操作,您必须指定窗口的选项卡或文档

像这样

tell application "Safari"
    tell window 1
        set current tab to make new tab with properties {URL:"...."}
        delay 5
        do JavaScript "some command" in current tab
    end tell
end tell
还是这个

tell application "Safari"
    tell window 1
        set current tab to make new tab with properties {URL:"...."}
        delay 5
    end tell
    do JavaScript "some command" in document 1 -- document 1 is the current tab of the front window
end tell

您是否尝试过使用一些简单的操作来测试javascript调用,例如
console.log(…)