I can open a web page by (browse-url "http://www.google.com"), but cannot open new tab by (browse-url "chrome://newtab"). Any workaround? I would like to have an Emacs shortcut to open a new chrome tab (on Mac and on Linux).

2 Answers 2

(defun browse-url-mac-chrome (url &optional _new-window)
  "Browse URL in Chrome.

Chrome protocol URL such as chrome://newtab is supported,
unlike `browse-url-default-macosx-browser'."
  (interactive (browse-url-interactive-arg "URL: "))
    ;; https://apple.stackexchange.com/a/271709/132365
    `("set myLink to \"" ,url "\""
      "tell application \"Google Chrome\""
      "    activate"
      "    tell front window to make new tab at after (get active tab) with properties {URL:myLink}"
      "end tell")

The AppleScript code is from https://apple.stackexchange.com/a/271709/132365, since I don't know how to use that language.

  • It works for mac, thanks! Is there any similar command works for Linux?
    – AhLeung
    Commented Apr 4, 2018 at 6:14
  • @AhLeung I don't know. I don't have a Linux computer.
    – xuchunyang
    Commented Apr 4, 2018 at 6:32

(shell-command "chrome about:blank") will come close to doing what you want in a cross-platform manner; the only problem is that the URL bar won't be focused. Unfortunately, chrome chrome://newtab opens in a new window.

This Ask Ubuntu answer suggests xdotool search --onlyvisible --classname 'google-chrome' windowactivate --sync key --clearmodifiers --window 0 ctrl+t; on my system this does exactly what you'd like. Only works on Linux, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.