2010-01-19 74 views

回答

9

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

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

Firefox应该可以了,但显然已经被当前的3.5.x版本打破了。 – 2010-01-19 05:31:34

+0

漂亮!这适用于所有三种浏览器,使用“Firefox”,“Google Chrome”和“Safari”作为应用程序字符串。 – 2010-01-19 06:19:46

5

这里的另一种方式做到这一点在Safari中没有使用JavaScript:

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

下面是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 
+4

这个脚本应该得到更多的赞扬IMO,因为它不需要您在重新加载之前将浏览器带入焦点 - 这是关键。 – bitwit 2011-12-09 22:54:44

+1

您也可以使用“第一个标签”而不是“活动标签”。 – blockloop 2015-05-23 19:21:22

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

  • 保存的服务,例如,使用名称铬刷新

系统预置

  • 开放系统预置>键盘
  • 快捷方式选项卡,选择服务
  • 分配一个新的快捷方式

A screengrab showing System Preferences keyboard shortcut tab

相关问题