使用osascript发送通知。
klaxon的Python项目详细描述
克拉克森
从终端或python程序发送mac os(或notifiers)通知。
这对于需要推送通知时特别有用 对于一些长期运行的后台任务。
类似于terminal-notifier ruby gem, 但是POSIX兼容并且能够通过 notifiers库。
安装
对于命令行使用,建议的安装方法是通过pipx。
pipx install klaxon
当然,klaxon也可以安装pip。
pip install klaxon
用法
终端
# blank notification klaxon # with custom message klaxon --message "this is the message body"# pipe message from other programecho"this is the message body"| klaxon --
Python
fromklaxonimportklaxon,klaxonify# send a notificationklaxon(title='hello, klaxon',subtitle='hola',message='it me')# we can decorate our functions to have# them send notifications at termination@klaxonifydefhello(name='world'):returnf'hello, {name}'@klaxonify(title='oh hai',output_as_message=True)deffoo():return"This will be the message body."
非MacOS通知
即移动电子邮件松弛
您需要在安装klaxon时附加notifiers
。
pipx install klaxon[notifiers]
您需要一个~/.config/klaxon/config.toml
或pyproject.toml
文件,其中
tool.klaxon
在顶层配置的命名空间。后者的价值观
重写前者中的值。
enable-notifiers
需要设置为true
,并且需要一个[[notifiers]]
键。
后者将确定传递给notifiers.notify
方法的参数。
例如:
~/.config/klaxon/config.toml
enable-notifiers=true[[notifiers]]name='slack'# see https://api.slack.com/incoming-webhooks#getting-startedwebhook_url={{yourwebhookurl}}[[notifiers]]name='pushover'user={{yourusertoken}}token={{yourapplicationtoken}}
喂!现在,从Klaxon发送的消息将被推到Slack和Pushover。