通过 AppleScript 脚本实现,脚本代码如下:
tell application "Google Chrome"
set current_tab to active tab in the front window
set the_url to the URL of current_tab
tell application "Safari" to open location the_url
end tell
tell application "System Events"
if frontmost of process "Safari" then
set visible of process "Safari" to false
else
set frontmost of process "Safari" to true
end if
end tell
将内容保存为.scpt
文件。
- 打开「自动操作(Automator)」应用,在「选择文稿类型」中选择「快速操作」;
- 在左侧资源库中搜索「运行 AppleScript」,双击或拖拽到流程面板;
- 将脚本输入框中的
(* Your script goes here *)
替换为do shell script "/usr/bin/osascript /path/to/your/script.scpt"
。或者,将(* Your script goes here *)
替换为上面的代码; - 设置「工作流程收到」为「无输入」,「位于」设置为「Google Chrome」;
- 「Cmd+S」保存,命名为「在 Safari 中打开」或你喜欢的名称。
保存后是一个.workflow
文件,位于用户目录-资源库-service目录。之后如果要重命名,目前只能删掉 workflow 文件再重新添加;
打开「偏好设置-键盘-快捷键-服务」,在「通用」中找到上面添加的服务,选中后可以看到设置快捷键提示。
设置快捷键后,就可以在 Chrome 窗口中直接以快捷键,将当前页面在 Safari 中打开;或者在菜单栏的「服务」中点击服务。