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

发布于 2024-08-18 04:05:27 字数 210 浏览 4 评论 0原文

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

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

How can I tell Chrome or Firefox to reload the document in the top window? Here's what I'm using for Safari:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

北方的巷 2024-08-25 04:05:27

这是 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

Here's the code for Chrome:

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

Or more concisely:

tell application "Google Chrome" to tell the active tab of its first window
    reload
end tell
盗心人 2024-08-25 04:05:27

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

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

I do not think Firefox or Chrome have special Applescript support, but you can send the keystrokes (Cmd-R) to refresh the page:

tell application "Firefox"
    activate
    tell application "System Events" to keystroke "r" using command down
end tell
旧情别恋 2024-08-25 04:05:27

这是在 Safari 中不使用 JavaScript 的另一种方法:

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

Here's another way to do it in Safari without using JavaScript:

tell application "Safari"
    tell its first document
        set its URL to (get its URL)
    end tell
end tell
苏璃陌 2024-08-25 04:05:27

Automator

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

显示 Automator 中文档类型对话框的屏幕截图

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

 

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

显示自动窗口操作的屏幕截图

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

系统偏好设置

  • 打开系统偏好设置 > 键盘
  • 快捷方式选项卡中,选择服务
  • 分配新的快捷方式

显示系统偏好设置键盘快捷键选项卡的屏幕截图

Automator

  • Open Automator and choose a New Document
  • Choose Service

A screengrab showing the document type dialog in Automator

  • Set Service receives to no input
  • Choose Run AppleScript action from the action list.
  • Paste the following code in the script:
tell application "Google Chrome" to tell the active tab of its first window
reload
end tell

A screengrab showing the automator window actions

  • Save the the service, for example, using the name Chrome Refresh

System Preferences

  • Open System Preferences > Keyboard
  • In the Shortcuts tab, choose Services
  • Assign a new shortcut

A screengrab showing System Preferences keyboard shortcut tab

原来是傀儡 2024-08-25 04:05:27

上面的以下答案效果很好,但如果它是焦点中的最后一个选项卡/窗口,使用它们会导致 DevTools 在新选项卡中刷新。我不希望 DevTools 在新选项卡中刷新,我只想刷新第一个选项卡,无论最后一个焦点/活动如何,这对我来说效果很好。留给也在寻找这个用例的人。

tell application "Google Chrome"
  activate
  tell application "System Events"
    tell process "Google Chrome"
      keystroke "r" using {command down, shift down}
    end tell
  end tell
end tell

The following answers above work well but using them result in DevTools refreshing in a new tab if it was the last tab/window in focus. I don't want DevTools to refresh in a new tab, I just want the first tab to refresh regardless of last focus/active and this worked well for me. Leaving for someone searching for this use case as well.

tell application "Google Chrome"
  activate
  tell application "System Events"
    tell process "Google Chrome"
      keystroke "r" using {command down, shift down}
    end tell
  end tell
end tell
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文