cristianmiranda / dotfiles

🤖 ~/dotfiles
http://dotfiles.cmiranda.ar
6 stars 3 forks source link

Listen to incoming libnotify notifications using DBus #7

Closed cristianmiranda closed 4 years ago

cristianmiranda commented 4 years ago

Relace dunst scripting with a better and more solid approach using DBus notifications.

See https://askubuntu.com/questions/89279/listening-to-incoming-libnotify-notifications-using-dbus

import glib
import dbus
from dbus.mainloop.glib import DBusGMainLoop

def print_notification(bus, message):
  keys = ["app_name", "replaces_id", "app_icon", "summary",
          "body", "actions", "hints", "expire_timeout"]
  args = message.get_args_list()
  if len(args) == 8:
    notification = dict([(keys[i], args[i]) for i in range(8)])
    print notification["app_name"], notification["summary"], notification["body"]

loop = DBusGMainLoop(set_as_default=True)
session_bus = dbus.SessionBus()
session_bus.add_match_string("type='method_call',interface='org.freedesktop.Notifications',member='Notify',eavesdrop=true")
session_bus.add_message_filter(print_notification)

glib.MainLoop().run()
cristianmiranda commented 4 years ago

Covered on #4