1
我試圖在AppleScrip中運行一個小小的Javascript,但沒有喜悅,也找不到問題。Javascript in Applescript
如果我在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
我不得不使用JavaScript,因爲我試圖單擊並從下載的鏈接是動態的,所以我不能隨便給AppleScript的靜態地址。
我不知道,也許有更好的方法來做到這一點?
任何幫助將不勝感激,謝謝!
你有沒有試過用'console.log(...)'等簡單的動作來測試javascript調用? – Ilya