系统通知中, 已经允许emacs了, 但是发送通知没有效果, 不管是start-process还是在eshell中调用, 都没有效果
而在终端中使用同样的命令, 可以发送成功
系统是macOS 15.2, emacs是27.1图形版
系统通知中, 已经允许emacs了, 但是发送通知没有效果, 不管是start-process还是在eshell中调用, 都没有效果
而在终端中使用同样的命令, 可以发送成功
系统是macOS 15.2, emacs是27.1图形版
发通知可以看一下这个函数 org-show-notification,
对于 macOS 好像可以这样:(ns-do-applescript (format "display notification \"%s\" with title \"Org mode notification\"" (replace-regexp-in-string "\"" "#" notification)))
没 mac 设备没试
def notifyUser(title, message):
"""
Notify the user some message with tile.
For example, in mac, it will pop up message.
"""
cmdstr = '/usr/bin/osascript -e \'display notification "%s" with title "%s"\'' % (
message,
title,
)
os.system(cmdstr)
我用的emacs 27比较老, 好像没这个函数ns-do-applescript
这个应该也是调用的外部命令osacript, 和terminal-notifer类似.
terminal-notifer现在可以了, 不指定sender为org.gnu.Emacs就可以, 很奇怪, 明明已经允许emacs发通知了
更奇葩的是: terminal-notifer在item2中运行时, 可以指定sender为org.gnu.Emacs, 而且通知图标还能显示emacs的图标. 但是在emacs里面反倒不能指定sender, 简直无语
我直接在命令行调用osascript发不了, 没有效果, macOS的通知系统挺魔幻
系统设置里,"通知"那里把应用都加进去了吗?
iterm2加了, emacs也加了.
iterm2里运行osascript -e "display notification \"aaa\" with title \"bbb\""
没有效果
iterm2运行terminal-notifier -title "aa" -message "bb" -sound Glass
, 有效果, 功能正常
iterm2运行terminal-notifier -title "aa" -message "bb" -sound Glass -sender org.gnu.Emacs
, 也有效果, 功能正常, 而且通知能显示emacs图标
m2 芯片和 intel 芯片, iterm2 执行 terminal-notifier -title "aa" -message "bb" -sound Glass
都没有效果…
macOS 14.5 (23F79)
上面的代码执行是有效果的, 之前没效果是因为开启了勿扰模式…
(defun notify-osx (title msg)
(call-process "terminal-notifier"
nil 0 nil
"-group" "Emacs"
"-title" title
;; "-sender" "org.gnu.Emacs"
"-message" msg
"-active" "org.gnu.Emacs"))
上面的代码可以在 Emacs 中发送系统通知, 但是如果不注释 sender
的话, 消息就会隐藏到通知中心里;只有注释掉 sender 才可以在前台显示通知的小窗。
代码来自 .emacs.d/lisp/init-func.el at 5341a41e2b100c1228eb2438aa5a83927857cfb0 · devbins/.emacs.d · GitHub
在终端中运行同样命令可以指定"-sender" "org.gnu.Emacs"
, 而且通知消息会显示emacs图标, 在emacs中反倒不能指定, 难以理解