【问题标题】:How do I send a notification with python to mac notifications center?如何使用 python 向 mac 通知中心发送通知?
【发布时间】:2019-09-30 03:32:40
【问题描述】:

我想用 python 代码向我的 mac 的通知中心发送通知。

我在 macOS Mojave 版本 10.14.6 上使用 python3,Atom 作为我的编辑器。我尝试过使用不同的方法,例如 notify2(没有用,dbus 存在我无法解决的问题)和 notify-send(回复 RuntimeError: Unsupported operating system: darwin)。所以,现在,我正在尝试使用 OS 模块。到目前为止,这是我的代码:

import os
mstr='Hello'
os.system('notify-send '+mstr)

当我从终端运行它时,它会输出sh: notify-send: command not found。如果我从 Python 的默认编辑器 IDLE 运行它,什么也不会发生。

我该怎么办?还有其他发送通知的方法吗?

【问题讨论】:

标签: python python-3.x macos


【解决方案1】:

对不起!在浏览网络后,我找到了解决此问题的方法。在这里!

import os
mstr='Hello'
os.system("osascript -e 'display notification \"hello world!\"\'")```

【讨论】:

    猜你喜欢
    • 2012-07-27
    • 2021-04-18
    • 1970-01-01
    • 2014-03-03
    • 1970-01-01
    • 2020-07-14
    • 2017-02-24
    • 2016-02-24
    • 1970-01-01
    相关资源
    最近更新 更多