是否可以将击键发送到 Safari 中的网页?

Is it possible to send keystrokes to a web page in Safari?

我想使用 applescript 在 google 搜索中切换到第一个 link。试过这个:

tell application "Safari" to activate
tell application "System Events"
       repeat 17 times
       keystroke tab using control down
       end repeat
end tell

但这只会快速循环打开的标签页。我google四处寻找,找不到任何解释如何将击键发送到 Safari 中当前打开的选项卡的内容。

Is it possible to send keystrokes to a web page in Safari?

有可能。

你问题中的 AppleScript code 循环通过 tabs 因为那是 键盘快捷键 ⌃Tab 可以。

只需要 tab,从 keystroke tab using control down command.[=13= 中删除 using control down ]