3

When editing code or org-mode, I often need the URL of the page I'm viewing in Google Chrome. Is there a way to do this from Emacs? Or with an external helper script if necessary?

An example use case would be editing code:

# See <insert current link to StackOverflow on bash variables>
if [[ -z "${param// }" ]]; then foo; fi
  • 1
    What operating system are you using? How to get data from another application will depend on the platform. – glucas Nov 11 '16 at 18:36
  • partial answer might be in unix.stackexchange.com/questions/241658/… – icarus Nov 12 '16 at 0:47
  • I'm on Linux and Mac, but it'd be nice to have a way for all OS's to get it and wrap it in an elisp function. – Joe Nov 12 '16 at 7:46
  • I use alt d to quickly highlight the omnibox in Chrome, and the same shortcut works fine in most browsers. It's a pretty quick way to copy and paste a link to Emacs. – DoMiNeLa10 Nov 12 '16 at 13:26
1

Mac OS

You can use org-mac-link.el, it produces an Org link since it can know not only URL but also TITLE by using AppleScript. You can install it via

  • Install org-plus-contrib from Org ELPA
  • or install org-mac-link from MELPA
  • or contrib/lisp/ under Org source code (get it via Git repo or tarball)

by the way, even you install via ELPA, you still need to setup autoloads for commands you need or simply require the feature since org-mac-link.el doesn't setup its autoload cookies.

GNU/Linux

As far as I know, X11 doesn't provide tool like AppleScript. So you need to do it manually or some automation tool. For example, to get URL:

  1. Switch to Google Chrome
  2. Move cursor to Address Bar and select (or copy) URL
  3. Switch to Emacs (or Terminal if you are running Emacs in it)
  4. Yank from PRIMARY selection (or clipboard)

You can use tools such as xdotool(1) to simulate the above steps, I tried this way a few days ago in grab-x-link.el, it supports Firefox and Chromium but not Chrome, it works for me in most cases.


There is also org-protocol.el. Basically, you register a URL scheme / protocol for emacsclient, then you find some way (such as Bookmarklet in web browser) to activate URL in that scheme.

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.