在 Mac OS X 上的 Chrome 中打开标签的全局键盘快捷键

aar*_*ron 8 keyboard-shortcuts google-chrome macos

配置全局键盘快捷键以在 Mac OS X 上的 Chrome 中打开标签的最佳方法是什么?

注意事项

  • 它应该尽可能简单,所以我不想每次都<alt><tab>+ <cmd><t>
  • 这必须是全局的,所以如果我<cmd><return>在 Mail.app 中按我的快捷方式(恰好是 ),它需要将 Chrome 带到前面并打开一个新标签
  • 它需要打开新的标签页,即chrome://newtab,不是像这样的网站http://www.google.com
  • 最高优先级是开快快快,次要优先级是易于配置

当前解决方案

现在,我已经将Quicksilver.app配置为 每当我按下时执行以下 AppleScript(或 osascript<cmd><return>

#!/usr/bin/osascript

tell application "Google Chrome Canary"
    activate
end tell

tell application "System Events"
    tell process "Google Chrome Canary"
        tell menu bar 1
            tell menu bar item "File"
                tell menu "File"
                    click menu item "New Tab"
                end tell
            end tell
        end tell
    end tell
end tell
Run Code Online (Sandbox Code Playgroud)

这样做的问题是,如果我上次运行它已经有一段时间了,它最多可能需要 5 秒。我已将其编译为 *.app,但这比使其成为可执行文件要慢osascript。我不害怕尝试开发上述脚本的编译版本,但我是 UNIX/web 开发人员,而不是 OS X,而且我对系统不熟悉。

Dan*_*eck 6

您可以运行以下终端命令(例如在 bash 脚本中):

open -a "Google Chrome" chrome://newtab
Run Code Online (Sandbox Code Playgroud)

这将导致应用程序Google Chrome打开 URL chrome://newtab,从而打开一个新选项卡。

不幸的是,谷歌浏览器没有在chrome://Launch Services 中注册URL 类型,它会认为这是一个文件路径。

要解决此问题,请右键单击 Google Chrome 的应用程序包,选择Show Package Contents,打开Contents目录并Info.plist在文本编辑器中进行编辑。

搜索CFBundleURLTypes。编辑以下几行以添加由 a 指示的行+

<key>CFBundleURLTypes</key>
<array>
+   <dict>
+       <key>CFBundleURLName</key>
+       <string>Chrome Internal URLs</string>
+       <key>CFBundleURLSchemes</key>
+       <array>
+           <string>chrome</string>
+       </array>
+   </dict>
    <dict>
        <key>CFBundleURLName</key>
        <string>Web site URL</string>
Run Code Online (Sandbox Code Playgroud)

保存并关闭。将谷歌浏览器的应用程序包移动到不同的目录,然后再返回,以使启动服务接受更改(如果它不起作用,请注销并重新登录)。

然后,open像开头描述的那样运行。


一旦成功,您最好的选择是运行一个执行open命令的 shell 脚本,该脚本又由您的启动器调用。由于我认为延迟是由osascript加载引起的,因此您在此处选择的几乎任何解决方案都应该足够快。


要半自动地编辑Info.plist文件(您必须对所有 Chrome 更新重复此操作),您可以PlistBuddy在终端中使用。首先,创建一个文件,例如chrome-url.plist使用以下内容命名的文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
  <dict>
    <key>CFBundleURLName</key>
    <string>Chrome Internal URLs</string>
    <key>CFBundleURLSchemes</key>
    <array>
        <string>chrome</string>
    </array>
    </dict>
</array>
</plist>
Run Code Online (Sandbox Code Playgroud)

然后,您可以使用以下内容来修补 Chrome 的Info.plist

/usr/libexec/PlistBuddy -c "Merge '/path/to/chrome-url.plist' :CFBundleURLTypes" /Applications/Google\ Chrome.app/Contents/Info.plist


w00*_*00t 5

Chrome 现在支持内置的全局快捷方式,我创建了Global New Tab Shortcut扩展来利用它。

安装它,分配一个快捷方式并将范围设置为全局,您就可以超快速地访问 OmniBar。