views:

87

answers:

1

hi,

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.

+3  A: 
(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))))
huaiyuan
Thanks huaiyuan. Works as expected. When i run C-o, it opens, and a emacs creates a buffer "*Async shell Command*". I think this buffer is for output of stdout. Is there a way to suppress this window opening unless there is actually ouput or error messages? Thanks!
Vinh Nguyen
On a related note I wrote a blog post on running an elisp function on each marked file:http://justinsboringpage.blogspot.com/2009/04/running-elisp-function-on-each-marked.html
justinhj