从 Dired 到 Finder
假设我们用 Dired 选中了几个文件,却想用 Finder 来管理,可以用下面的命令来把 Dired 中标记的文件「转化」为 Finder 里选中的文件:
(defun dired-finder-reveal-marked-files (files)
"Reveal marked FILES in Finder.
FILES are a list of absolute filename.
FILES are in the same directory."
(interactive (list (dired-get-marked-files)))
(when files
(do-applescript
(format
(concat "tell application \"Finder\"\n"
" activate\n"
" tell (make new Finder window) to set target to POSIX file \"%s\"\n"
" set selection to {%s}\n"
"end tell")
(file-name-directory (car files))
(mapconcat
(lambda (file)
(format "POSIX file \"%s\"" file))
files
", ")))))
效果演示:
- Dired 中标记三个文件
- M-x dired-finder-reveal-marked-files
- 完成!Finder 窗口打开并标记那三个文件
从 Finder 到 Dired
反向实现比较困难,我能想到的方法是利用 org-protocol://
,懒得折腾了,目前实现了个「用 Dired 打开当前 Finder 窗口目录」,不管选不选中了:
tell application "Finder"
POSIX path of (target of front window as alias)
tell application "Emacs" to open result
end tell