UP | HOME

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

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

1. 依赖外部Python的旧版

安装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镜像库,方便下载。

2. 使用内建函数的新版

[2024-10-28 周一 16:15]:使用内建函数,减少外部依赖。

(defun fw/appt-disp-windows (min-to-app new-time msg)
  (let ((id (w32-notification-notify
             :level "info"
             :title msg
             :body "⚠️有新提醒,请查看Emacs!⚠️")))
    (run-at-time 1 nil #'w32-notification-close id)))

▲ 编辑于 [2024-10-28 周一 16:16] | © Published by Emacs 31.0.50 (Org mode 9.7.16) on [2024-11-21 周四 00:22] | RSS