2

macOS动态定时弹提醒 - Est's Blog

 1 year ago
source link: https://blog.est.im/2022/stdout-08
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

macOS动态定时弹提醒

Posted 2022-07-20 | stdout

上班地方有个付费计时,想在倒计时结束前在电脑弹个提醒,手动结束计费,趴下来API了。接下来就是如何弹窗了。

本来想用macOS自带的 UNUserNotificationCenter 通过 PyObjC 撸个弹窗,遇到两个问题:

  1. 系统自带的 PyObjC 太老了。还是Python2.7的。在/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
  2. 只能兼容旧款的 NSUserNotification,状态为 macOS 10.8–11.0 Deprecated
    新的API调用需要进程签名。
    codesign -dv --verbose=4 /usr/bin/python2.7

只有官方的python2.7签名了 anaconda/miniconda 的都没签名。算了。还是直接 AppleScript 走起

osascript  -e 'display notification "还有1分钟到达时辰" with title "准时付费" sound name "Frog"'

想在这个提示里加一个 snooze 1分钟功能,但是好像无法支持。罢了。2333


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK