How to hide notifications inside the notification icon in the system tray

hello Forum i have a quick question regarding the notifications
i want to send notification through a python program and i want it to stay hidden in the notification widget in the system tray after timeout , i have tried 2 different approaches

first approach

import subprocess

def send_persistent_notification(title, message, timeout=-1):
    subprocess.run([
        'notify-send', title, message,
        '--hint=int:transient:0',
        '--hint=int:resident:1',
        '-t', str(timeout)
    ])

send_persistent_notification("Persistent Notification", "This notification stays in the tray!", timeout=5000)

Second approach

import dbus

def send_persistent_notification(summary, body):
    bus = dbus.SessionBus()
    notification_object = bus.get_object('org.freedesktop.Notifications', '/org/freedesktop/Notifications')
    notify_interface = dbus.Interface(notification_object, 'org.freedesktop.Notifications')

    hints = {'resident': dbus.Boolean(True), 'urgency': dbus.Byte(1)}

  
    notify_interface.Notify("dunst", 0, "", summary, body, [], hints, -1)

send_persistent_notification("Reminder", "This notification will stay in the tray until dismissed.")

both are sucessfully sending notifications but it does not stay there after timeout any solutions please tell me , im out of options. :slightly_smiling_face:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.