Is there a way in the org mode syntax to create a link and to define which browser to open the link in? I have some links that I want to open in a different browser than my default one.

  • Do these links have some shared characteristics (other than that you want to open them with some other browser)? – Stefan Oct 31 '18 at 14:12

More than two years later, and possibly not exactly what you were looking for, but still:

    M-x customize-option RET org-file-apps RET

Feel free to customise.

  • 1
    IIUC this specifies in general which app is used for which kind of link, whereas the OP wanted something specific to a particular link. – Stefan Oct 31 '18 at 14:12

You can define a function that grabs the URL at point and calls one of browse-url-<browser name> functions. Taking the example of Chromium:

(defun browse-url-at-point-chromium (&optional ARG)
  (let ((url (browse-url-url-at-point)))
    (if url
    (browse-url-chromium url ARG)
      (error "No URL found"))))

And bind that function to a key:

(define-key org-mode-map (kbd "C-RET") 'browse-url-at-point-chromium)

This also works in other modes, such as mu4e (email in Emacs):

(define-key mu4e-view-mode-map (kbd "C-RET") 'browse-url-at-point-chromium)

macOS pitfalls

On macOS, the browsers with a Graphical User Interface (GUI) are not linked to shell executables, so Emacs can't see them in the default browse-url-chromium function, for example. So you need the additional step of giving Emacs the path to the executable:

(setq browse-url-chromium-program "/Applications/Chromium.app/Contents/MacOS/Chromium")

macOS and Safari

If you want Safari on macOS, it has the additional problem that the executable does not take arguments (see this thread). One solution from there is to call AppleScript to tell Safari to open the URL. The shell command is:

/Applications/Safari.app/Contents/MacOS/Safari & sleep 1 && osascript -e 'tell application "Safari" to open location "http://www.google.com"'

Another is to use open -a Safari <URL> in bash and start-process in ELisp:

(defun browse-url-at-point-safari ()
  (let ((url (browse-url-url-at-point)))
    (if url
            (start-process (concat "mozilla " url) nil "mozilla" url)
      (error "No URL found"))))

I was unable to make either of these work and found it easier to use another browser, such as Chromium.

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.