Growl notification in python

2.6k views Asked by At

Using Growl in python but having no luck with anything appearing. Using the following code. Running on OSX Lion with Growl 1.3.3. Anyone got this working?

import Growl

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

There are 2 answers

0
Matthew Schinckel On

It looks like there is a new python bindings library for growl: gntp

You may have better luck with that.

3
Dan Benamy On

Here's another solution that works with Growl 1.2. I don't have 1.3 to test with. It's better than most of the solutions floating around because you don't have to turn on growl networking.

From http://wiki.python.org/moin/MacPython/Growl/AppleScriptSupport:

$ pip install appscript

and run this:

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')