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

Mek*_*ire 5 macos emacs dock automator emacsclient

如何在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,但都没有奏效。

bra*_*der 9

从航站楼出发

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

$ type emacsclient
emacsclient is /usr/local/bin/emacsclient
Run Code Online (Sandbox Code Playgroud)

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

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


从 macOS 图形用户界面

要从 Dock 或 Spotlight 等启动emacsclient,可以轻松使用 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 配置文件等。


law*_*ist 1

一个想法是创建一个 applescript,它可以完成原始发布者想要的任何操作,并使用 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
Run Code Online (Sandbox Code Playgroud)