我想通过双击打开在 Finder 中选择的组织模式文件。但由于我在守护程序模式下使用Emacs,因此我想使用emacsclient
命令。
因此,主要想法是将命令 emacsclient -c posixPathToFile
包装在 AppleScript App 中以打开它。
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 中打开”即可运行并打开该文件。
第一种方法有什么问题?
最佳答案
好的,我解决了我的问题。问题来自于我对 ScriptEditor 和 Automator 之间差异的误解。如果我使用 Automator 创建应用程序并使用以前的脚本而不是使用 ScriptEditor 创建应用程序,那么它会按预期工作。
可以通过在 Automator 中创建应用程序并运行 shell 脚本(而不是将命令包装在 Ascript 中)来简化该过程。
关于macos - 如何使用 `emacsclient` 命令双击 OS X 中的 EMACS 文件来打开它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45548847/