在Mac OS X上如何从Dock启动带图形界面的Emacsclient

9
如何在Mac OS X上从Dock(或终端)启动带有GUI的Emacsclient? EmacsWiki 描述 如何使用Automator创建“从Dock启动的Emacs”应用程序。它对我有用,但我不想启动Emacs,而是想启动Emacsclient。因此,我尝试将/Applications/Emacs.app/Contents/MacOS/Emacs替换为/Applications/Emacs.app/Contents/MacOS/bin/emacsclient/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -c,但两者都无效。

1
如果这里没有人回答你的问题,你可能想在 Emacs StackExchange 上提问。只是建议一下。 - Chakravarthy Raghunandan
1
如果您正在使用emacs-mac端口,请注意其中的emacsclient有一些错误:https://github.com/railwaycat/homebrew-emacsmacport/issues/52 - Braham Snyder
2个回答

9

从终端

您可以在 shell 中使用 type 查找适当的路径以使用 emacsclient(假设从该 shell 中可以使用 emacsclient -c):

$ type emacsclient
emacsclient is /usr/local/bin/emacsclient

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

/usr/local/bin/emacsclient -n -c -a ""


从macOS GUI启动

要从Dock或Spotlight启动emacsclient,可以使用Automator。Automator内置于macOS。

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

/usr/local/bin/emacsclient -n -c -a "" -- "$@"

然后更改“传递输入”:使用“作为参数”而不是“到标准输入”。

添加的"$@"是将任何可选参数传递给此shell脚本的位置。这样,您就可以将文件名传递给emacsclient以打开文件。Automator自动在您单击使用我们刚刚制作的应用程序打开文件时传递此文件名。这还允许您将应用程序设置为某些文件类型的默认应用程序。


随时随地,灵活方便

运行上述Shell命令的另一种方法是使用skhd (链接)。学习起来更加复杂,但最终使得设置大量Shell命令变得更加容易,并能快速访问。

例如,您可以在macOS的任何地方将"Ctrl-o"设为进入一个您命名为open_app的模式,然后按下"e"打开emacsclient,按下"d"打开emacs --debug-init,按下"t"运行emacs --adv-timers,按下"f"打开Firefox,按下"F"打开第二个Firefox配置文件等。


1
khd链接已经失效。 - Glenn

1
一种想法是创建一个苹果脚本,按照原帖作者的要求执行,并使用像 Platypus 或 Automator 这样的东西将其打包成应用程序。请参阅 https://superuser.com/questions/685111/basic-setup-of-emacs-server-under-osx 获取其他想法,例如使用 --daemon 命令行参数而不是将 (server-start) 放置在用户配置文件中。
这里是一个苹果脚本示例:
#  (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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接