Growl Notifications from a Web Server

落爺英雄遲暮 提交于 2019-12-10 05:12:22

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/1109786/growl-notifications-from-a-web-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!