Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
notify - Gnome Notification Script
#!/usr/bin/python
# Filename notify
# Description Show a notification in Gnome3
# Author Drew Fradette <http://www.github.com/drewfradette>
# Last Updated 2012-04-18
# Usage notify -t "Eat cheese" -m "It tastes delicious"
#######################################################
import pynotify
import sys
class Notify:
def __init__(self, title, message, timeout=500, icon='dialog-information'):
self.title = title
self.message = message
self.timeout = timeout
self.icon = icon
def show(self):
pynotify.init(self.title)
n = pynotify.Notification(self.title, self.message, self.icon)
n.set_timeout(int(self.timeout))
n.show()
if __name__ == '__main__':
from optparse import OptionParser
usage = 'Usage: notify [-t <title> | --title=<title>] [-m <message> | --message=<message>] ([-i <icon> | --icon=<icon> ] [-n <timeout> | --timeout=<timeout>])'
parser = OptionParser(usage=usage)
parser.add_option('-t', '--title', action='store', dest='title',
default='Notification', help='The title of the notification.')
parser.add_option('-m', '--message', action='store', dest='message',
default='', help='The message on the notofication.')
parser.add_option('-n', '--timeout', action='store', dest='timeout',
default=500, help='The time to display the notification.')
parser.add_option('-i', '--icon', action='store', dest='icon',
default='dialog-information', help='The icon to display.')
(options, args) = parser.parse_args()
options = vars(options)
n = Notify(**options)
n.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment