macos - 如何使用 `emacsclient` 命令双击 OS X 中的 EMACS 文件来打开它?

标签 macos emacs automator emacsclient

我想通过双击打开在 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 中)来简化该过程。

shell script Automator

关于macos - 如何使用 `emacsclient` 命令双击 OS X 中的 EMACS 文件来打开它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45548847/

相关文章:

php - 如何在 Mac OS X 上将 PHP shell 脚本作为 Automator 操作执行

ruby - 为什么 Process.fork 会使 OS X 上的 Ruby 变慢?

python - 如何使 python 程序从命令行普遍可执行?

ios - objective-c : Accessing properties of an object instance that's in an array that's a property of an object

macos - 似乎并不是我的所有 HTML 页面都在某些浏览器中加载

javascript - 如何使用适用于 mac yosemite 的 javascript automator (JAX) 获取网页的原始 html?

emacs - 在 emacs 中使用钢筋?

java - 在 Eclipse 中显示带有下划线的驼峰式单词

emacs 删除选择模式自行禁用

macos - Automator:如何使用“从列表中选择”操作?