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

时间:2010-01-19 05:13:30

标签: macos firefox google-chrome applescript

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

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

4 个答案:

答案 0 :(得分:39)

以下是Chrome的代码:

tell application "Google Chrome"
    tell the active tab of its first window
        reload
    end tell
end tell

或者更简洁:

tell application "Google Chrome" to tell the active tab of its first window
    reload
end tell

答案 1 :(得分:9)

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

tell application "Firefox"
    activate
    tell application "System Events" to keystroke "r" using command down
end tell

答案 2 :(得分:5)

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

tell application "Safari"
    tell its first document
        set its URL to (get its URL)
    end tell
end tell

答案 3 :(得分:1)

的Automator

  • 打开 Automator 并选择新文档
  • 选择服务

A screengrab showing the document type dialog in Automator

  • 服务接收设为无输入
  • 从操作列表中选择运行AppleScript 操作。
  • 将以下代码粘贴到脚本中:

tell application "Google Chrome" to tell the active tab of its first window
reload
end tell

A screengrab showing the automator window actions

  • 保存服务,例如,使用名称 Chrome Refresh

系统偏好设置

  • 打开系统偏好设置> 键盘
  • 快捷方式标签中,选择服务
  • 指定新的快捷方式

A screengrab showing System Preferences keyboard shortcut tab