glennji.com

Because life's too short to do it the RIGHT way

python

May 23

Evolution new mail notification

    #!/usr/bin/env python
    import dbus
    import dbus.glib
    import gobject

    bus = dbus.SessionBus()
    bus.get_object("org.freedesktop.DBus","/org/freedesktop/DBus")
    notify_service = bus.get_object('org.freedesktop.Notifications', '/org/freedesktop/Notifications')
    notify_interface = dbus.Interface(notify_service, 'org.freedesktop.Notifications')

    def newmail_handler(msg, msg2):
        notify_interface.Notify("evo-notify", 0, '', "New Email", msg, [], {}, -1)
    
    bus.add_signal_receiver(newmail_handler, dbus_interface = "org.gnome.evolution.mail.dbus.Signal", signal_name = "Newmail")
    
    loop = gobject.MainLoop()
    loop.run()

Python

Python-logo.jpgPython is a flexible programming language which can run as an interpreted script or precompiled for speed. It is dynamically-typed and automatically memory-managed. Python is used largely on Linux, although it is available on other operating systems too, and integration with various subsystems and libraries makes it ideal for some home automation tasks.

Example scripts

Libraries and APIs

  • gps.py and geo.py - gpsd and geocoding
  • mpdclient - mpd
  • xPL toolkit for Python
  • (Controlling Ekiga - VOIP softphone)
  • (Controlling Pidgin - IM client)
  • (Controlling VLC - Video player)