2

我想通过双击打开在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 中打开”工作并打开该文件。

第一种方法有什么问题?

4

1 回答 1

1

好的,我解决了我的问题。问题来自我对ScriptEditorAutomator之间区别的误解。如果我使用 Automator 创建应用程序并使用以前的脚本而不是使用 ScriptEditor 创建应用程序,那么它会按预期工作。

可以通过在 Automator 中创建应用程序并运行 shell 脚本而不是在 Ascript 中包装命令来简化该过程。

shell 脚本自动化器

于 2017-08-08T10:28:13.093 回答