如何使用`emacsclient`命令在OS X上双击EMACS文件?

如何使用`emacsclient`命令在OS X上双击EMACS文件?

问题描述:

我想打开Finder中选定的组织模式文件,方法是双击它。但由于我在守护进程模式中使用Emacs,我想使用emacsclient命令。如何使用`emacsclient`命令在OS X上双击EMACS文件?

因此,主要想法是将命令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打开”

现在选择一个文件,然后右键单击并callig服务>“打开保存为在Emacs中“工作并打开文件。

第一种方法有什么问题?

+0

如何使应用程序与鸭嘴兽,并从那里运行脚本,并与该鸭嘴兽应用程序相关联自己喜欢的文件类型? – lawlist

+0

想法不是使用第三方工具 – m0ll3art

+0

下面是一个标题为“Mac *上的Emacsdaemon和Emacsclient”的相关主题,它有几个示例:https://emacs.stackexchange.com/questions/141/emacsdaemon-and- emacsclient-on-mac,这里是reddit上的另一个相关线程:https://www.reddit.com/r/emacs/comments/1wu2ja/a_tip_for_os_x_users_using_emacs_daemon/?st=j639vmk6&sh=8bb51e73 Google关键字:“** emacsclient automator app emacs发现者**“ – lawlist

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

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

shell script Automator