Skip to content
Alex R edited this page Sep 1, 2021 · 5 revisions

Welcome to the siglo wiki!

Command-line scan the dbus for SMS messages:

#!/usr/bin/env python3
import gi.repository.GLib as glib

import dbus
from dbus.mainloop.glib import DBusGMainLoop

def scan_for_notifications():
    DBusGMainLoop(set_as_default=True)
    monitor_bus = dbus.SessionBus(private=True)
    try:
        dbus_monitor_iface = dbus.Interface(monitor_bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus'), dbus_interface='org.freedesktop.DBus.Monitoring')
        dbus_monitor_iface.BecomeMonitor(["interface='org.freedesktop.Notifications', member='Notify'"], 0)
    except dbus.exceptions.DBusException as e:
        print(e)
        return
    monitor_bus.add_message_filter(notifications)
    mainloop = glib.MainLoop()
    mainloop.run()

def notifications(bus, message):
    alert_dict = {}
    for arg in message.get_args_list():
        if isinstance(arg, dbus.Dictionary):
            if arg["desktop-entry"] == "sm.puri.Chatty":
                alert_dict["category"] = "SMS"
                alert_dict["sender"] = message.get_args_list()[3]
                alert_dict["message"] = message.get_args_list()[4]
            print(alert_dict)
    if len(alert_dict) > 0:
        print(alert_dict)

scan_for_notifications()
Clone this wiki locally