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
(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.
-
It works for mac, thanks! Is there any similar command works for Linux?– AhLeungCommented Apr 4, 2018 at 6:14
-
(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.