如何使用python向mac通知中心发送通知?

2024-05-13 04:08:08 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我在MacOSMojave10.14.6版上使用python3,Atom是我的编辑器。我尝试过使用不同的方法,比如notify2(它不起作用,dbus有一个问题,我无法解决)和notify send(它回答RuntimeError: Unsupported operating system: darwin)。所以,现在,我正在尝试使用操作系统模块。这是我目前为止的代码:

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

当我从终端运行它时,它输出sh: notify-send: command not found。如果我从Python的默认编辑器IDLE运行它,则不会发生任何事情。在

我该怎么办?是否有其他发送通知的替代方法?在


Tags: 方法代码sendosmacnotify编辑器中心
0条回答
网友
1楼 · 发布于 2024-05-13 04:08:08

对不起!我在网上转了一圈后找到了解决办法。在这里!在

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

相关问题 更多 >