python中的Growl通知

时间:2012-05-15 20:48:15

标签: python macos growl

在python中使用Growl但是没有出现任何运气。使用以下代码。使用Growl 1.3.3在OSX Lion上运行。任何人都有这个工作?

import Growl

notifier = Growl.GrowlNotifier(applicationName='mzgrowl', notifications=['alive'])
notifier.register()
notifier.notify('alive', 'mzgrowl', 'test message')

2 个答案:

答案 0 :(得分:2)

看起来有一个新的用于咆哮的python绑定库:gntp

你可能会有更好的运气。

答案 1 :(得分:0)

这是另一个适用于Growl 1.2的解决方案。我没有1.3测试。它比大多数解决方案更好,因为你不必打开咆哮网络。

来自http://wiki.python.org/moin/MacPython/Growl/AppleScriptSupport

$ pip install appscript

并运行:

from appscript import *

# connect to Growl
growl = app('GrowlHelperApp')

# Make a list of all the notification types 
# that this script will ever send:
allNotificationsList = ['Test Notification', 'Another Test Notification']

# Make a list of the notifications 
# that will be enabled by default.      
# Those not enabled by default can be enabled later 
# in the 'Applications' tab of the growl prefpane.
enabledNotificationsList = ['Test Notification']

# Register our script with growl.
# You can optionally (as here) set a default icon 
# for this script's notifications.
growl.register(
    as_application='Growl Appscript Sample', 
    all_notifications=allNotificationsList, 
    default_notifications=enabledNotificationsList, 
    icon_of_application='PythonIDE')

# Send a Notification...
growl.notify(
    with_name='Test Notification', 
    title='Test Notification', 
    description='This is a test Appscript notification.', 
    application_name='Growl Appscript Sample')
    # You can optionally add an icon by adding one of these as the last arg:
    # icon_of_application="Script Editor.app")
    # icon_of_file="file:///Users/someone/Growl")
    # image_from_location="file:///Users/someone/pictures/stopWatch.png")

# Another one...
growl.notify(
    with_name='Another Test Notification', 
    title='Another Test Notification :) ', 
    description='Alas - you won\'t see me until you enable me...', 
    application_name='Growl Appscript Sample')