Applescript运行Javascript,并在提示中插入文本

Applescript to run Javascript with text inserted in prompt

本文关键字:提示 插入文本 运行 Javascript Applescript      更新时间:2024-03-12

我使用Applescript在Safari中打开YubNub的Javascript提示。偶尔我会更频繁地使用搜索范围,比如"ebay"ect,我希望Yubnub命令已经在提示中键入,这样我就可以直接键入搜索了。我尝试了以下脚本在提示中键入"ebay",但它只显示一个空提示。如有任何帮助,我们将不胜感激。谢谢

脚本:

    tell application "Safari"
do JavaScript          
              "javascript:Qr=prompt('','');if(Qr)location.href='http://www.yubnub.org/parser/parse?         command='+escape(Qr)" in current tab of first window
    end tell
     delay 0.3
    tell application "System Events" to key code 14
    tell application "System Events" to key code 11
    tell application "System Events" to key code 0
    tell application "System Events" to key code 16

这与我在这个问题中描述的问题相同。基本上,当您从applescript打开提示时,整个applescript都会暂停,直到您取消提示为止。和另一个问题一样。请阅读以获得完整的解释。因此,你可以这样做。。。

set searchTerm to "ebay"
do shell script "/usr/bin/osascript -e 'delay 1' -e 'tell application '"System Events'" to keystroke '"" & searchTerm & space & "'"' > /dev/null 2>&1 &"
tell application "Safari"
    activate
    set newTab to make new tab in window 1
    set current tab of window 1 to newTab
    do JavaScript "javascript:Qr=prompt('','');if(Qr)location.href='http://www.yubnub.org/parser/parse?         command='+escape(Qr)" in current tab of first window
end tell