2

When using dired in emacs, how can I open an url file in a web browser outside emacs?

  • 1
    have you tried browse-url-at-point ? – Chakravarthy Raghunandan Dec 5 '16 at 15:19
  • Here is a snippet that I could use on OSX (if I wanted to): (let ((file (dired-get-file-for-visit))) (start-process "my-process" nil "open" "-a" "/Applications/Firefox.app/Contents/MacOS/firefox" file)). If you are on a different OS, then you can probably eliminate "open" and "-a", but you may need to add something specific to your OS to ensure that the browser receives input focus (if so desired) -- on OSX, that is what the "-a" is for. If you want to open multiple files, then you'll need to use dired-get-marked-files and loop through the list of marked files. – lawlist Dec 5 '16 at 15:38
  • @lawlist browse-url should be even better for this. – user12563 Dec 5 '16 at 17:24
  • @DoMiNeLa10 The OP is actually talking about a file format: fileinfo.com/extension/url . The best solution in my mind is ergoemacs.org/emacs/emacs_dired_open_file_in_ext_apps.html – xuhdev Dec 6 '16 at 10:01
  • Thanks both of you! @lawlist: for some reason I got am error message on your solution, but will not investigate it since I found a perfect solution offered by DoMiNeLa10 and xuhdev. – myotis Dec 6 '16 at 11:08
1

You can add a key binding, such as C-RET to open any files in system defined default external programs such as xdg-open on Linux and open on macOS. In this way, URL files are opened by default browsers. A detailed approach is available on ErgoEmacs: http://ergoemacs.org/emacs/emacs_dired_open_file_in_ext_apps.html

| improve this answer | |
  • By the way, how did you bind C-RET? When I tried with this: (global-set-key (kbd "C-return") 'xha-open-in-external-app) I got the error "C- must prefix a single character, not return" – myotis Dec 6 '16 at 11:31
  • @myotis (define-key dired-mode-map (kbd "<C-return>") 'xah-open-in-external-app) – xuhdev Dec 7 '16 at 5:47

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.