In Emacs on Mac OSX, is there a function to reveal the current file in the Finder?
A bit late, but I just created a script based on this. When invoked from a dired buffer, it opens the folder.
https://github.com/kaz-yos/reveal-in-osx-finder (new link)
EDIT 2014-02-06 Now available on MELPA: M-x list-packages should list reveal-in-finder among other packages.
See here for use. https://github.com/kaz-yos/reveal-in-osx-finder
EDIT 2014-04-08 I slightly updated the script (below). This should be helpful in a dired buffer.
(NEW in 0.3.0) If M-x reveal-in-finder is invoked in a dired buffer, it will open the current folder in the OS X Finder. It will also highlight the file at point if available.
EDIT 2015-08-03 The package was renamed to reveal-in-osx-finder.el to avoid possible confusion with other kinds of "finders".
Solution #1:: The second solution below was the initial answer, but I am now using something slightly different that also maximizes the Finder window. So, here is the alternative solution (which works for directories and files):
(defun dired-open-in-finder ()
"This function contemplates that we are in columns view in Finder (Command+3),
rather than list view (Command+2)."
(interactive)
(let ((path (dired-get-file-for-visit))
(display-pixel-height (number-to-string (display-pixel-height)))
(display-pixel-width (number-to-string (display-pixel-width))))
(when path
(let* ((maximize
(concat
"tell application \"Finder\" to set the bounds of the front Finder window to "
"{0, 0, " display-pixel-width ", " display-pixel-height "}\n"))
(script
(concat
"tell application \"Finder\"\n"
" set frontmost to true\n"
" make new Finder window to (POSIX file \"" path "\")\n"
maximize
"end tell\n")))
(start-process "finder" nil "osascript" "-e" script)))))
Solution #2: I don't remember where I got this from -- if anyone knows, please let me know and I'll post a citation to the author -- thanks.
(defun open-finder ()
(interactive)
(let ((path (or (buffer-file-name) (dired-file-name-at-point)))
dir file)
(when path
(setq dir (file-name-directory path))
(setq file (file-name-nondirectory path)))
(open-finder-1 dir file)))
(defun open-finder-1 (dir file)
(let ((script
(if file
(concat
"tell application \"Finder\"\n"
" set frontmost to true\n"
" make new Finder window to (POSIX file \"" (expand-file-name dir) "\")\n"
" select file \"" file "\"\n"
"end tell\n")
(concat
"tell application \"Finder\"\n"
" set frontmost to true\n"
" make new Finder window to {path to desktop folder}\n"
"end tell\n"))))
(start-process "osascript-getinfo" nil "osascript" "-e" script)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With