function to call same shell command in dired

681 Views Asked by At

i'd like to be able to call the same shell command on the marked files in dired without the need for emacs to prompt the command input as the command will always be the same. in particular, the command is "open" (for mac os x).

i tried to hack the function dired-do-shell-command in dired-aux.el but i don't understand the interactive line.

at the end of the day, i'd like to be able to bind this function to C-o for dired-mode so that i don't have to use mac os x's Finder to navigate files and open them. this will allow me to move to emacs entirely.

thanks.

1

There are 1 best solutions below

2
On BEST ANSWER
(defun dired-open ()
  (interactive)
  (dired-do-async-shell-command
   "open" current-prefix-arg
   (dired-get-marked-files t current-prefix-arg)))

(define-key dired-mode-map (kbd "C-o") 'dired-open)

Edit:

We may use save-window-excursion to protect the existing window configuration from being messed up by the output buffer:

(defun dired-open ()
  (interactive)
  (save-window-excursion
    (dired-do-async-shell-command
     "open" current-prefix-arg
     (dired-get-marked-files t current-prefix-arg))))