激活一个Emacs的功能与一个AppleScript的最有效的方法 [英] Most efficient method of activating an Emacs function with an applescript
问题描述
有没有更好的方法,在Emacs激活函数的AppleScript,而不是打开迷你缓冲区启动功能?还有一个就是把我的手指离开控制键与快捷键启动的AppleScript(这样的Emacs不会把它注册为一个命令)需要延迟,且有键入函数的名称接连延迟进入小缓冲区。理想情况下,我想告诉在引擎罩Emacs在无需打开小缓冲区的运行特定功能的。下面是一个简单的AppleScript激活的Emacs,并与的Mx
打开小缓冲区,然后键入函数的名称(码头
)和preSS返回键。应工作是否Emacs的方法是presently打开(或隐藏在前面)或关闭。
FYI:对于新手程序员喜欢自己,这里是一个备忘单关键codeS:<一href=\"http://apple.stackexchange.com/questions/36943/how-do-i-automate-a-key-$p$pss-in-applescript/36947#36947?newreg=9adf36816f4245d69f0900ec09588057\">http://apple.stackexchange.com/questions/36943/how-do-i-automate-a-key-$p$pss-in-applescript/36947#36947?newreg=9adf36816f4245d69f0900ec09588057
修改:较短的方法是建立在Emacs的快捷键是连接到一个函数(全球设置键(KBD&LT; F6&GT; )(拉姆达()(互动)(dired/应用程序)))
- 例如,F6以激活该功能,然后用键code 97
为F6键。但是,它仍然将是很好的学习如何运行指定按名称Emacs的功能(带一个AppleScript),而无需打开迷你缓冲区。
告诉应用程序系统事件
告诉应用程序/Users/HOME/.0.data/.0.emacs/Emacs.app/Contents/MacOS/Emacs来激活
延迟0.3
关键code 53#逃生
关键code 7#x的
关键code 2·D
关键code 31#Ø
关键code 8·C
关键code 40#ķ
延迟.1
关键code 36#回报
告诉结束
或
告诉应用程序系统事件
告诉应用程序/Users/HOME/.0.data/.0.emacs/Emacs.app/Contents/MacOS/Emacs来激活
延迟0.3
关键code 97#F6
告诉结束
修改:修订草案(基于@Francesco答案) - 它要求(服务器启动)
是里面的Emacs启动文件(例如, init.el
)。 IF Emacs的GUI已经运行,然后运行 emacsclient
没有在此之前暂停; ELSE,启动Emacs的GUI(停顿1秒服务器加载),然后运行 emacsclient
。
上is_running(的appName)
告诉应用程序系统事件到(进程名)中包含的appName
结束is_running
设置EmacsRunning为is_running(Emacs的)
如果再EmacsRunning
告诉应用程序/Users/HOME/.0.data/.0.emacs/Emacs.app/Contents/MacOS/Emacs来激活
做shell脚本/Users/HOME/.0.data/.0.emacs/Emacs.app/Contents/MacOS/bin/emacsclient -e'(dired \\/应用程序\\)'
其他
告诉应用程序/Users/HOME/.0.data/.0.emacs/Emacs.app/Contents/MacOS/Emacs来激活
延迟1
做shell脚本/Users/HOME/.0.data/.0.emacs/Emacs.app/Contents/MacOS/bin/emacsclient -e'(dired \\/应用程序\\)'
万一
我不知道有关AppleScript,但你不能使用的 emacsclient
做到这一点?
一旦你已经开始在现有的Emacs实例的服务器(<大骨节病>的Mx 骨节病> 服务器启动
<大骨节病> RET 骨节病>),你可以运行类似:
emacsclient -e(称之为交互'坞)
评估任意LISP code到Emacs。
Is there a better method to activate a function in Emacs with an applescript instead of opening the minibuffer to launch the function? There is a delay that is needed to take my finger off of the control key to launch the applescript with a keyboard shortcut (so that Emacs doesn't register it as a command), and there is another delay after typing the name of the function into the minibuffer. Ideally, I'd like to tell Emacs under-the-hood to run a particular function without opening the minibuffer. The following is a simple applescript to activate Emacs, and open the minibuffer with M-x
, and type the name of the function (dock
), and press the return key. The method should work whether Emacs is presently open (hidden or in the front) or closed.
FYI: For the novice programmers like myself, here is a cheat-sheet for key codes: http://apple.stackexchange.com/questions/36943/how-do-i-automate-a-key-press-in-applescript/36947#36947?newreg=9adf36816f4245d69f0900ec09588057
EDIT: A shorter method would be to set up a keyboard shortcut within Emacs that is attached to a function (global-set-key (kbd "<f6>") (lambda () (interactive) (dired "/Applications")))
-- e.g., F6 to activate the function, and then use key code 97
for the F6 key. However, it would still be nice to learn how to specify running an Emacs function by name (with an applescript) without opening the minibuffer.
tell application "System Events"
tell application "/Users/HOME/.0.data/.0.emacs/Emacs.app/Contents/MacOS/Emacs" to activate
delay .3
key code 53 # escape
key code 7 # x
key code 2 # d
key code 31 # o
key code 8 # c
key code 40 # k
delay .1
key code 36 # return
end tell
or
tell application "System Events"
tell application "/Users/HOME/.0.data/.0.emacs/Emacs.app/Contents/MacOS/Emacs" to activate
delay .3
key code 97 # F6
end tell
EDIT: Revised draft (based on the answer by @Francesco) -- it requires that (server-start)
be inside the Emacs startup file (e.g., init.el
). IF Emacs GUI is already running, then run emacsclient
without a pause prior thereto; ELSE, launch Emacs GUI (pause 1 second for the server to load) and then run emacsclient
.
on is_running(appName)
tell application "System Events" to (name of processes) contains appName
end is_running
set EmacsRunning to is_running("Emacs")
if EmacsRunning then
tell application "/Users/HOME/.0.data/.0.emacs/Emacs.app/Contents/MacOS/Emacs" to activate
do shell script "/Users/HOME/.0.data/.0.emacs/Emacs.app/Contents/MacOS/bin/emacsclient -e '(dired \"/Applications\")'"
else
tell application "/Users/HOME/.0.data/.0.emacs/Emacs.app/Contents/MacOS/Emacs" to activate
delay 1
do shell script "/Users/HOME/.0.data/.0.emacs/Emacs.app/Contents/MacOS/bin/emacsclient -e '(dired \"/Applications\")'"
end if
I don't know about applescript, but can't you use emacsclient
to do this?
Once you have started the server in your existing Emacs instance (M-xserver-start
RET), you can run something like :
emacsclient -e "(call-interactively 'dock)"
to evaluate arbitrary lisp code into Emacs.
这篇关于激活一个Emacs的功能与一个AppleScript的最有效的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!