UP | HOME

emacs-使用Windows-Toasts的python库为Emacs创建Windows11通知提醒

[2024-04-07 周日 10:14]

安装pip包

pip install windows-toasts

~/.emacs.d/ 中新建 notify.py ,内容如下:

import sys,os
from urllib.parse import unquote
from windows_toasts import Toast, WindowsToaster, ToastDisplayImage
toaster = WindowsToaster('Emacs Agenda')
newToast = Toast()
newToast.text_fields = [unquote(sys.argv[1])]
newToast.AddImage(ToastDisplayImage.fromPath(unquote(sys.argv[2])+"/org/phone/emacs.png"))
toaster.show_toast(newToast)

将先前的elisp函数 fw/appt-disp-windows 改为

(defun fw/appt-disp-windows (min-to-app new-time msg)
    "A custom `appt-disp-window-function' which uses the PowerShell module 'BurntToast'"
    (shell-command (concat "python -X utf8 "(file-truename user-emacs-directory) "notify.py " (url-encode-url msg )" " (url-encode-url (file-truename user-emacs-directory))))

经测试能正常提醒。使用python库的好处在于规避powershell的安装、策略设置过程,可以利用国内的pip镜像库,方便下载。

▲ 编辑于 [2024-08-22 周四 11:09] | © Published by Emacs 30.0.50 (Org mode 9.7.10) on [2024-08-22 周四 11:25] | RSS