2016-09-13 88 views
3

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

EmacsWiki describes如何使用Automator创建“Emacs Dock”应用程序。它为我工作,但我不想推出Emacs,但Emacsclient。所以,我试图用/Applications/Emacs.app/Contents/MacOS/bin/emacsclient/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -c替换/Applications/Emacs.app/Contents/MacOS/Emacs,但两者都不起作用。

+1

如果用户没有在这里回复,你可能需要在emacs stackexchange中提出这个问题。只是说。 –

+0

如果您使用的是emacs-mac端口,请注意它的'emacsclient'有点儿错误:https://github.com/railwaycat/homebrew-emacsmacport/issues/52 –

回答

1

一个想法是创建一个可以做任何原始海报需求的applescript,并使用类似platypus或automator的应用程序将其包装在一个应用程序中。请参阅https://superuser.com/questions/685111/basic-setup-of-emacs-server-under-osx以获取其他建议,例如使用​​命令行参数,而不是在用户配置文件中放置(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 
2

编辑:现在我建议你使用khd,而不是完成一个Automator的应用程序这一点,因为使用KHD是更快,更灵活。 khd允许您以模态方式在指定的按键序列上运行$SHELL(您的默认shell)命令。例如,你可以把上的任意键全局前缀,让我们说控制 - Ø,只是为了打开应用程序:控制后 - Ø,按ē可以运行emacsclient -n -c -a ""(或者,例如,对于新的Finder窗口,使用f)。

这一点可能是这个样子你.khdrc

khd mode openapp color 0xFF932092 
khd mode openapp prefix on 
khd mode openapp timeout 5 

# from default mode, press ctrl - o to enter openapp mode 
ctrl - o : khd -e "mode activate openapp" 

# then press e to open emacs and return to normal operation 
openapp - e : khd -e "mode activate default";\ 
       emacsclient -n -c -a "" 

# or f to open Finder and return to normal operation 
openapp - f : khd -e "mode activate default";\ 
       open -a Finder 

# or--in case we change our mind--press escape to return directly 
# to normal operation instead of opening an application 
openapp - escape  : khd -e "mode activate default" 

我还是有,虽然对其他情况的A​​utomator的应用程序,其中一个.app文件是方便(比如设置为打开一个文件类型的默认应用程序要成为emacsclient - 有可能也可能不是将这类事情直接设置为shell命令的更好方法,但Automator应用似乎已足够)。


的Automator应用:

您可以找到合适的路径在您的外壳采用which(假设从所述外壳emacsclient -c作品)到emacsclient:

$ which emacsclient 
/usr/local/bin/emacsclient 

使用上述路径(和一些emacsclient标志,您可能需要以及详情请参阅$ man emacsclient):

/usr/local/bin/emacsclient -n -c -a "" -- "[email protected]"