Python发布osx通知 [英] Python post osx notification
本文介绍了Python发布osx通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用python,我想向OSX通知中心发布一条消息. 我需要使用哪个库?我应该在Objective-C中编写一个程序,然后从python调用该程序吗?
Using python I am wanting to post a message to the OSX Notification Center. What library do I need to use? should i write a program in objective-c and then call that program from python?
更新
如何访问10.9的通知中心功能,例如按钮和文本字段?
How do I access the features of notification center for 10.9 such as the buttons and the text field?
推荐答案
您应该安装 terminal-notifier 首先使用Ruby,例如:
You should install terminal-notifier first with Ruby for example:
$ [sudo] gem install terminal-notifier
然后您可以使用以下代码:
And then you can use this code:
import os
# The notifier function
def notify(title, subtitle, message):
t = '-title {!r}'.format(title)
s = '-subtitle {!r}'.format(subtitle)
m = '-message {!r}'.format(message)
os.system('terminal-notifier {}'.format(' '.join([m, t, s])))
# Calling the function
notify(title = 'A Real Notification',
subtitle = 'with python',
message = 'Hello, this is me, notifying you!')
然后去:
这篇关于Python发布osx通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文