激活最前面的Safari并运行Javascript


0

我正在尝试在Safari上运行Javascript,最重要的是它。

tell (application "Safari" whose frontmost is true) to do JavaScript theScript in current tab of first window

但我收到这样的错误:

execution error: Cant get application "System Events" whose frontmost of it = true. Access not allowed. (-1723)

我在哪里弄错了?

Answers:


1

你的脚本试图告诉s.th. 到据称已经“最前面”的Safari应用程序。是吗?!?
您只能通过属性识别或激活未知元素(“其......是......”)
这样做:第一个应用程序...

如果你想要 “Safari”成为“最前沿”你最好写:

tell application "Safari"
    activate
    do JavaScript theScript in current tab of first window
end tell
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.