2012-05-15 6 views
6

Verwendung von Growl in Python, aber kein Glück mit etwas erscheint. Verwenden Sie den folgenden Code. Läuft unter OSX Lion mit Growl 1.3.3. Hat jemand das funktioniert?Growl Benachrichtigung in Python

import Growl 

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

Fehlermeldung? Stapelverfolgung? Oder funktioniert es einfach nicht? – BluePeppers

+0

funktioniert einfach nicht :( –

+0

Bit mehr Info. Ich habe den gleichen Code auf OSX Lion versucht, läuft Growl 1.2.2 und es funktioniert perfekt. Aber immer noch kein Glück mit Growl 1.3.3. Haben die Python Bindings geändert? –

Antwort

2

Es sieht aus wie eine neue Python-Bindings Bibliothek für Knurren ist: gntp

Sie mit, dass mehr Glück haben.

0

Hier ist eine andere Lösung, die mit Growl 1.2 funktioniert. Ich habe keine 1.3 zu testen. Es ist besser als die meisten anderen Lösungen, weil Sie das Knurren von Netzwerken nicht aktivieren müssen.

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

$ pip install appscript 

und führen Sie diese:

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

Ab dem 13.07.14 funktioniert das nicht. Kopiert und eingefügt direkt in Texteditor, stellte sicher, dass ich appscript installiert hatte, und es bricht immer in der ersten Zeile des Codes (ohne die Import-Zeile). In IDLE, bekam bei "Knurren = app ('GrowlHelperApp') und bekam: "Traceback (jüngste Aufforderung zuletzt): File" " Linie 1 in Knurren = appscript.app ('GrowlHelperApp') NameError: Name 'appscript' ist nicht definiert " – Tango

+0

@Tango Und du hast" pip install appscript "ausgeführt? –

+0

Ja, ich muss ehrlich sagen, an dieser Stelle, da ich mit verschiedenen Elementen eines Programms arbeite, einschließlich Handel mit Python und AppleScript, plus die Kommunikation mit mehreren Modems und Benachrichtigungen, dass ich im Moment nicht kopieren kann, was ich gestern gemacht habe und sicher bin, dass ich alles gleich mache - wenn ich also zukünftige Probleme finde, werde ich ein Update bereitstellen, Aber für den Moment, als ich es nicht zur Arbeit bringen konnte, ging ich zu einer anderen Reihe von Aufgaben über und hielt die Informationen nicht über das hinaus, was oben steht. (Mit anderen Worten, ich kann nicht wiederholen und verifizieren, bu t wenn ich kann, werde ich wieder kommentieren.) – Tango