Home

Open file in external application from dired in emacs

July 27, 2026

Out of the box, RET is bound to dired-find-file. W runs browse-url-of-dired-file for example to view a HTML file in the browser, but it can also open files externally. But what if you wanted to open a video by pressing RET? Or get more granular? Here are two packages performing similar functions.

(use-package dired-open
  :ensure t
  :config
  ;; macOS uses the open command (Launch Services handles associations)
  (setq dired-open-extensions
        '(("mp4"  . "open")
          ("mkv"  . "open")
          ("mov"  . "open")
          ("avi"  . "open")
          ("webm" . "open")
          ("mp3"  . "open")
          ("ogg"  . "open")
          ("pdf"  . "open"))))

Below is another approach, tailored for Linux.

(use-package openwith
  :ensure t)

(setq openwith-associations
      (list
       (list (openwith-make-extension-regexp
              '("mpg" "mpeg" "mp3" "mp4" "m4v"
                "avi" "wmv" "wav" "mov" "flv"
                "ogm" "ogg" "mkv" "webm"))
             "gio"
             '("open" file))
       (list (openwith-make-extension-regexp
              '("pdf"))
             "evince"
             '(file))))

(openwith-mode 1)

What does this all mean? Emacs is not just a text editor, it is a means for adapting your computer to work the way you expect it to work. I like to think of my emacs config as a ball of yarn. A bunch of threads tying everything together. There is no right or wrong way to use emacs, but often you run into situations where searching around the internet doesn’t always find you the most effective solution. You can search and search and still be lost.

This Stackoverflow question, How to use an external program as the default way to open PDFs from Emacs? prompted me to follow Lei Zhao’s suggestion for a bit. But after some time, it didn’t quite feel right and I ended up pursuing other solutions.