I have Emacs installed with brew install emacs-mac --HEAD --with-cocoa --with-gnutls --with-librsvg --with-imagemagick. I have the final .app binary in the OS X Dock.

If I drag a file onto the Dock icon, the default behavior opens it in the last-activated frame, even if it is on a different desktop. I'd like files to open in a new frame in the current desktop when drag-and-dropped onto the icon. Is this behavior possible? Yes, because this is emacs. Can anyone suggest a place to begin implementing this?

  • 1
    I don't use the Brew or dropping stuff in Dock icons, but I have looked into altering ns-find-file so that files opened from the Finder.app get displayed in certain select frames (using a custom function and let-binding the display-buffer-alist). Why not try adding a message to ns-find-file and drop your file on the Dock and see if the message gets displayed? If it does, then "Bingo!". If not, then "Go Fish!". Here is a link to a modified version of ns-find-file: stackoverflow.com/questions/18346785/…
    – lawlist
    Jul 7, 2016 at 16:39

1 Answer 1


Until someone suggest a better implementation, I over-write dnd-open-local-file to open in a new frame instead of a new window:

(setq dnd-open-file-other-frame t)    
(defun dnd-open-local-file (uri _action)
  (let* ((f (dnd-get-local-file-name uri t)))
    (if (and f (file-readable-p f))
      (if dnd-open-file-other-frame
          (find-file-other-frame f)
        (find-file f))
      (error "Can not read %s" uri))))
  • It seems like the default behavior has changed to this since the answer was written. I would like it to open in my existing frame, but it always opens a new frame. I don't see any relevant variables in Emacs 29.2.
    – Barmar
    May 2 at 20:07
  • I think dnd isn't a default package. Needs to be installed.
    – mankoff
    May 3 at 22:05
  • apropos-variable finds other dnd-XXX variables, such as dnd-open-file-other-window so I think it's loaded.
    – Barmar
    May 3 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.