1

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).

| improve this question | | | | |
1
(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: "))
  (do-applescript
   (mapconcat
    #'identity
    ;; 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")
    "\n")))

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

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

(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.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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