使用emacsclient运行cron作业,但如果当前没有服务器打开运行emacs --batch模式

J S*_*pen 2 emacs bash crontab org-mode emacs24

由于emacs互锁文件,我想通过cron运行org-mobile命令但是使用emacsclient:

emacsclient -nw --eval "(org-mobile-pull)" --eval "(org-mobile-push)"
Run Code Online (Sandbox Code Playgroud)

但是如果没有运行emacs服务器,我希望命令能够使用emacs批处理模式运行:

emacs --batch --eval "(org-mobile-pull)" --eval "(org-mobile-push)"
Run Code Online (Sandbox Code Playgroud)

如果有人有任何想法,我不知道怎么这么好奇.

eve*_*_jr 6

我很好奇你最终想要完成什么?为什么不总是开始新的Emacs流程?额外的开销将是一小部分秒

在我2岁的MBP上:

%的时间的emacs --batch --eval零的emacs --batch --eval零0.03S 0.01S用户系统87%的CPU 0.054总

沿着当前路径,您可以检查退出代码,emacsclient 以决定是否应批量运行

if emacsclient --eval nil >/dev/null 2>&1; then echo "run client"; else echo "run emacs"; fi
Run Code Online (Sandbox Code Playgroud)

编辑:我看到你想编写锁窃窃问题的答案.查看我对这个问题的答案,用于ask-user-about-lock解决这个问题.

编辑:所以我的想法是重新定义ask-user-about-lock返回t.查看文档:

ask-user-about-lock是`userlock.el'中的自动加载的Lisp函数.

(询问用户关于锁定文件的对手)

当用户想要编辑文件时询问用户该怎么做但它被OPPONENT锁定.这个函数可以选择三件事:do(信号'文件锁定(列出文件OPPONENT))以避免编辑文件返回t(抓住文件上的锁)返回nil(编辑文件,即使它是锁定).您可以重新定义此功能,以您喜欢的任何方式在这三种选择中进行选择.

[背部]

脚本示例(记得chmod)

#!/usr/bin/env emacs --script

(defun ask-user-about-lock (file opponent)
  t)

(org-mobile-pull)
(org-mobile-push)
Run Code Online (Sandbox Code Playgroud)