我使用 Applescript 在 Safari 中打开 YubNub 的 Javascript 提示符。有时我更频繁地使用搜索范围,如“ebay”等,我希望 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
最佳答案
这与我在 this question 中描述的问题相同.基本上,当您从 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
关于javascript - Applescript 运行 Javascript 并在提示中插入文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20394562/