Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Growl Notifications from a Web Server

I notice that Growl allows for the possibility of Growl notifications from a website. Has anyone tried implementing this?

If so, what form did it take? Did you implement multi user support? And, can you provide any code examples (C# or Objective-C would preferable but I'm not that fussed)?

Rich

like image 798
kim3er Avatar asked Oct 15 '22 15:10

kim3er


1 Answers

There are GNTP (Growl Network Transport Protocol) bindings for various languages, a list of bindings can be found here - these allow you to send notifications from, say, a PHP script.

I wouldn't trust Growl's UDP system directly, but rather write a server that receives and stores notifications (maybe as a tiny web app), and a local script that routinely grabs any new messages via HTTP and Growls them. Not complicated at all, will be more reliable than UDP, and can queue up messages when your Growl'ing machine is powered-off or unreachable. Shouldn't take long to implement

Basically, server.php in pseudo-PHP (which could use Net_Growl):

<?php
if($_GET['action'] == "store"){
    $title = $_POST['title'];
    $message = $_POST['message'];
    $password = sha1($_POST['password']);
    if($password == "..."){
        store_in_database(sanitise($title), sanitise($message);
    }
} else {
    print(json_encode(get_notifications_from_database()));
    mark_notifications_as_read();
}
?>

client.py in pseudo-Python (which could use gntp):

while 1:
    time.sleep(60):
    data = urllib.urlopen("http://myserver.com/server.php?action=get&password=blah").read()
    for line in data:
        notif = json.decode(line)
        growl.alert(notif['title'], notif['message'])
like image 75
dbr Avatar answered Oct 20 '22 07:10

dbr