我想通过双击打开在Finder中选择的 org-mode 文件。但是由于我在daemon-mode中使用 Emacs ,所以我想为此使用该emacsclient
命令。
因此,主要想法是将命令包装emacsclient -c posixPathToFile
在 AppleScript应用程序中以打开它。
tell application "Finder"
set fileAlias to the selection as alias
set fileName to name of fileAlias
set posixPath to POSIX path of fileAlias
end tell
-- tell application "Emacs" to activate
try
do shell script "/usr/local/bin/emacsclient -c " & quoted form of posixPath
end try
我知道有些set
命令是不需要的。让我们假设这个脚本被保存为Xemacs.app
并且我将这个应用程序与始终打开的.org
文件相关联。
通过双击文件无法使用此应用程序,而是如果我在 Finder 中选择文件,然后独立调用Xemacs.app。为什么 ?我对 AppleScript 没有足够的信心来弄清楚会发生什么。
所以解决方法是使用 Automator 服务
on run {input, parameters}
set posixPath to POSIX path of input
tell application "iTerm" to do shell script "/usr/local/bin/emacsclient -c " & quoted form of posixPath
return input
end run
该服务保存为“在 Emacs 中打开”
现在选择一个文件并右键单击并调用服务>“在 Emacs 中打开”工作并打开该文件。
第一种方法有什么问题?