6

如何在 Mac OS X 上从 Dock(或者也可以从终端)使用 GUI 启动 Emacsclient?

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

4

2 回答 2

4

从航站楼

您可以在您的 shell 中找到适当的emacsclient使用路径type(假设emacsclient -c从所述 shell 中工作):

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

然后我们可以添加适当的 emacsclient 标志(详见$ man emacsclient)来打开 GUI:

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


从 macOS 图形用户界面

要从emacsclient例如 Dock 或 Spotlight 启动,使用 Automator 很容易。Automator 内置于 macOS 中。

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

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

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

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


从任何地方,灵活地

运行上述 shell 命令的另一种方法是使用skhd(link)skhd学习起来要复杂得多,但最终可以更容易地设置大量快速访问的 shell 命令。

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

于 2016-10-06T23:36:17.693 回答
1

一个想法是创建一个applescript,它可以执行原始海报所需的任何操作,并使用鸭嘴兽或自动机之类的东西将其包装在应用程序中。有关其他想法,例如使用命令行参数而不是放在用户配置文件中,请参阅https://superuser.com/questions/685111/basic-setup-of-emacs-server-under-osx 。--daemon(server-start)

这是一个示例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
于 2016-09-14T01:33:00.710 回答