Skip to content

Instantly share code, notes, and snippets.

@hidsh
Last active October 18, 2017 22:12
Show Gist options
  • Save hidsh/4602292 to your computer and use it in GitHub Desktop.
Save hidsh/4602292 to your computer and use it in GitHub Desktop.
Mac: open folder by Finder from Emacs
(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 \"" 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)))
(defun open-finder ()
(interactive)
(let ((path (buffer-file-name))
dir file)
(when path
(setq dir (file-name-directory path))
(setq file (file-name-nondirectory path)))
(open-finder-1 dir file)))
(defalias 'e 'open-finder)
@jiahut
Copy link

jiahut commented Sep 16, 2014

good job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment