Macos 在Mac OS X上使用GUI(从Dock)启动EmacClient

Macos 在Mac OS X上使用GUI(从Dock)启动EmacClient,macos,emacs,automator,dock,emacsclient,Macos,Emacs,Automator,Dock,Emacsclient,如何在Mac OS X上从Dock(或者也可以从终端)启动带有GUI的EmacClient EmacsWiki介绍了如何使用Automator创建“来自Dock的Emacs”应用程序。它对我有用,但我不想启动Emacs,而是EmacClient。所以我试图用/Applications/Emacs.app/Contents/MacOS/Emacs和/Applications/Emacs.app/Contents/MacOS/bin/emacsclient替换/Applications/Emacs.

如何在Mac OS X上从Dock(或者也可以从终端)启动带有GUI的EmacClient


EmacsWiki介绍了如何使用Automator创建“来自Dock的Emacs”应用程序。它对我有用,但我不想启动Emacs,而是EmacClient。所以我试图用
/Applications/Emacs.app/Contents/MacOS/Emacs
/Applications/Emacs.app/Contents/MacOS/bin/emacsclient
替换
/Applications/Emacs.app/Contents/MacOS/bin/emacsclient-c
,但两者都不起作用。

一个想法是创建一个应用程序脚本,它可以按照原始海报的要求做任何事情,并使用platypus或automator之类的工具将其封装到应用程序中。有关其他想法,请参阅,例如使用
--daemon
命令行参数,而不是将
(服务器启动)
放在用户配置文件中

下面是一个示例applescript:

#  (server-start) must be inside `init.el` or `.emacs` file.
#
#  This script can also be used in the terimal:  osascript path-to-script arguments
#  Terminal Example:
#  osascript /absolute/path/to/applescript/file "-e '(progn (dired \"/Applications\") (message \"Hello-World\!\"))'"

on run argv
    set arg to item 1 of argv
    set emacs to application "Emacs"
    set appIsRunning to emacs is running
    if appIsRunning then
        say "Emacs is already running."
        do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient " & arg
    else
    tell application "/Applications/Emacs.app/Contents/MacOS/Emacs" to activate
        say "Please wait five seconds for Emacs to load."
        delay 5
        do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient " & arg
    end if
end run
从终点站 您可以在shell中使用
type
找到
emacsclient
的适当路径(假设
emacsclient-c
在所述shell中工作):

然后,我们可以添加适当的EmacClient标志(有关详细信息,请参见
$man EmacClient
)以打开GUI:

/usr/local/bin/emacsclient-n-c-a”“


来自macOS GUI 要从Dock或Spotlight启动
EmacClient
,很容易使用Automator。macOS内置了自动机

选择创建“应用程序”,然后选择“运行Shell脚本”,并将上述调用的修改版本添加到
EmacClient

/usr/local/bin/emacsclient-n-c-a”“--“$@”

然后更改“传递输入”:使用“作为参数”而不是“to stdin”

添加的
“$@”
将放置传递到此shell脚本的任何可选参数。在这里,这允许您传递一个文件名以使用
emacsclient
打开。Automator会在您使用我们刚刚创建的应用程序单击打开文件时自动传入此文件名。这还允许您将应用程序设置为特定文件类型的默认应用程序


从任何地方,灵活地 运行上述shell命令的另一种方法是使用
skhd
的学习难度要大得多,但最终可以更轻松地通过快速访问设置大量shell命令


例如,您可以在macOS中的任何位置使“Ctrl-o”进入您命名的模式
open_app
,从该模式中,您可以按“e”打开
EmacClient
,按“d”打开
emacs--debug init
,按“t”运行
emacs--adv timers
,按“f”打开Firefox,按“f”打开第二个Firefox配置文件,等等。

如果人们不在此处回复,您可能希望在emacs stackexchange中询问此问题。如果您使用的是emacs mac端口,请注意它的
EmacClient
有点问题:khd链接现在已断开。
$ type emacsclient
emacsclient is /usr/local/bin/emacsclient