【问题标题】:Launch Emacsclient with GUI (from Dock) on Mac OS X在 Mac OS X 上使用 GUI(来自 Dock)启动 Emacsclient
【发布时间】:2017-01-20 18:09:40
【问题描述】:

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

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

【问题讨论】:

标签: macos emacs automator dock emacsclient


【解决方案1】:

从终端

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

$ 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 (link)skhd 的学习难度要大得多,但最终可以更轻松地设置大量快速访问的 shell 命令。

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

【讨论】:

  • 现在 khd 链接已失效。
  • 谢谢,已修复
【解决方案2】:

一个想法是创建一个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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-24
    • 1970-01-01
    • 1970-01-01
    • 2012-06-08
    • 1970-01-01
    相关资源
    最近更新 更多