Mac:在Chrome或Firefox中重新加载文档?

Mar*_*son 8 macos firefox applescript google-chrome

如何告诉Chrome或Firefox在顶部窗口重新加载文档?这是我用于Safari的内容:

osascript -e '
    tell application "Safari"
      activate
      do JavaScript "history.go(0)" in document 1
    end tell
'
Run Code Online (Sandbox Code Playgroud)

Ben*_*jie 39

以下是Chrome的代码:

tell application "Google Chrome"
    tell the active tab of its first window
        reload
    end tell
end tell
Run Code Online (Sandbox Code Playgroud)

或者更简洁:

tell application "Google Chrome" to tell the active tab of its first window
    reload
end tell
Run Code Online (Sandbox Code Playgroud)

  • 这个脚本需要更多的IMO,因为它不需要你在重新加载之前将浏览器聚焦 - 这是关键. (4认同)

Thi*_*ilo 9

我不认为Firefox或Chrome有特殊的Applescript支持,但您可以发送击键(Cmd-R)来刷新页面:

tell application "Firefox"
    activate
    tell application "System Events" to keystroke "r" using command down
end tell
Run Code Online (Sandbox Code Playgroud)


Ned*_*ily 5

这是在不使用JavaScript的情况下在Safari中执行此操作的另一种方法:

tell application "Safari"
    tell its first document
        set its URL to (get its URL)
    end tell
end tell
Run Code Online (Sandbox Code Playgroud)