Script: gnotify.py

WARNING: this script has been disabled (not compatible with Python 3).

Notifications through Growl.
Author: tobypadilla — Version: 0.2 — License: GPL2
For WeeChat ≥ 0.3.0, requires: Growl, Growl Python Bindings.
Tags: notify, py2
Added: 2009-10-12 — Updated: 2009-10-14

Download GitHub Repository

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Author: tobypadilla <tobypadilla AT gmail DOT com>
# Homepage: http://github.com/tobypadilla/gnotify
# Version: 0.2
#
# gnotify requires Growl Python Bindings
# See here: http://growl.info/documentation/developer/python-support.php
# Requires Weechat 0.3.0
# Released under GNU GPL v2
#
# Copy weechaticn.png to /usr/local/share/pixmaps/ or change the path below
#
# gnotify is derived from notify http://www.weechat.org/files/scripts/notify.py
# Original author: lavaramano <lavaramano AT gmail DOT com>

import weechat, Growl, string

weechat.register("gnotify", "tobypadilla", "0.2", "GPL", "gnotify: Growl notifications for Weechat", "", "")

# script options
settings = {
    "show_hilights"             : "on",
    "show_priv_msg"             : "on",
    "sticky"                    : "on",
    "icon"                      : "/usr/local/share/pixmaps/weechaticn.png",
}

# Setup Growl Notification Class
class gNotifier(Growl.GrowlNotifier):
   applicationName = 'gnotify'
   notifications = ['highlight']
   # don't have/want the weechat icon? use ichat instead
   # applicationIcon = Growl.Image.imageWithIconForApplication("iChat")
   applicationIcon = Growl.Image.imageFromPath(weechat.config_get_plugin('icon'))

# Init everything
for option, default_value in settings.items():
    if weechat.config_get_plugin(option) == "":
        weechat.config_set_plugin(option, default_value)

# Hook commands to setup stickynote command
hook = weechat.hook_command("stickynote", "Set stickyness of gnotify Growl notifications",
    "[on|off|toggle]",
    "'on' makes sticky, 'off' makes not sticky, 'toggle' toggles stickyness",
    "on || off || toggle",
    "stickynote_cmd",
    "")

def stickynote_cmd(data, buffer, args):
    isSticky = weechat.config_get_plugin('sticky')
    if (args == 'toggle'):
        isSticky = ('on' if isSticky == 'off' else 'off')
    elif (args == 'on' or args == 'off'):
        isSticky = args
    else:
        weechat.prnt("","Invalid stickynote option: "+args)
    weechat.config_set_plugin('sticky',isSticky)
    weechat.prnt("","Growl notification stickyness is "+isSticky)
    return weechat.WEECHAT_RC_OK

# Hook privmsg/hilights
weechat.hook_signal("weechat_pv", "notify_show_priv", "")
weechat.hook_signal("weechat_highlight", "notify_show_hi", "")

# Functions
def notify_show_hi( data, signal, message ):
    """Sends highlight message to be printed on notification"""
    if weechat.config_get_plugin('show_hilights') == "on":
        show_notification("Weechat",  message)
    return weechat.WEECHAT_RC_OK

def notify_show_priv( data, signal, message ):
    """Sends private message to be printed on notification"""
    if weechat.config_get_plugin('show_priv_msg') == "on":
        show_notification("Weechat Private Message",  message)
    return weechat.WEECHAT_RC_OK

def show_notification(title,message):
    growl = gNotifier()
    growl.register()

    isSticky = (True if weechat.config_get_plugin('sticky') == "on" else False)
    growl.notify('highlight', title, message, "", isSticky)