You are not logged in.

#1 2021-12-13 11:49:01

Arciere
Member
From: Torino, Italy
Registered: 2020-10-07
Posts: 59

notify-send

Hi everyone,
I am a novice and the question to many could be stupid.
I don't understand what is the process to kill to delete a notification created with

notify-send

command. My goal is to kill this process to delete the old "critical" notification on the screen and replace it with a new one. For Ubuntu I have seen that

killall notify-osd

is used, but I use Arch Linux (with Gnome and Wayland) and it is not notify-osd that manages my notifications, apparently... I use Bash.
I have seen that there are versions of notify-send created by other people that eliminate just this problem, but I would like to have to install those versions only as a last resort.
Thank you in advance!


Arciere

Offline

#2 2021-12-13 12:19:21

seth
Member
Registered: 2012-09-03
Posts: 29,723

Re: notify-send

Whatever is the notification server (dunst, gnome, …), but this is not how this is done at all.
=> https://specifications.freedesktop.org/ … 01s09.html
When you request a notification, the notification server hands you back a cookie (well, it's a glorified integer…) that you can use on subsequent invocations.

"notify-send" is a cheap fire-and-forget tool, it won't allow you to do so.
dbus-send does unfortunately not support all types required by the interface, so you could use gdbus or qdbus.

Offline

#3 2021-12-13 15:00:14

Arciere
Member
From: Torino, Italy
Registered: 2020-10-07
Posts: 59

Re: notify-send

seth wrote:

Whatever is the notification server (dunst, gnome, …), but this is not how this is done at all.
=> https://specifications.freedesktop.org/ … 01s09.html
When you request a notification, the notification server hands you back a cookie (well, it's a glorified integer…) that you can use on subsequent invocations.

"notify-send" is a cheap fire-and-forget tool, it won't allow you to do so.
dbus-send does unfortunately not support all types required by the interface, so you could use gdbus or qdbus.

Thank you for your reply. I had already read this page this morning, but with very little results due to my poor preparation.
All I want is to have the "Do not turn off the computer" message appear on the screen when my script starts in the background, and have it disappear (or replace with something else) only when my script finishes.
I managed to set only the first part:

sudo -u $USER DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$UID/bus notify-send "DO NOT shut down your PC while you see this message!" --app-name="Test" --icon="/path/to/Icon.png" --urgency=CRITICAL

, but I miss the final part.
Wanting to try with gdbus or qdbus, would you have any suggestions on how to get started? I forgot that I use dbus-broker, are these two compatible with it?


Arciere

Offline

#4 2021-12-13 15:12:32

seth
Member
Registered: 2012-09-03
Posts: 29,723

Re: notify-send

There's a gdbus example in https://wiki.archlinux.org/title/Deskto … tions#Bash
Make the timeout on the first call "0" and on the second one "1" (this replaces the message w/ a 1ms timeout)
You'll either have to use a static UID (and hope that it's not in use) or read the output of the first call and use that later on.

W/o details on what *exactly* you want to achieve, that's all I can tell - if you've both dbus calls in the same script, you can use a variable for the UID - otherwise you'll have to store it in a temporary file.

Offline

#5 2021-12-13 16:18:06

Arciere
Member
From: Torino, Italy
Registered: 2020-10-07
Posts: 59

Re: notify-send

seth wrote:

There's a gdbus example in https://wiki.archlinux.org/title/Deskto … tions#Bash
Make the timeout on the first call "0" and on the second one "1" (this replaces the message w/ a 1ms timeout)
You'll either have to use a static UID (and hope that it's not in use) or read the output of the first call and use that later on.

W/o details on what *exactly* you want to achieve, that's all I can tell - if you've both dbus calls in the same script, you can use a variable for the UID - otherwise you'll have to store it in a temporary file.

Looking at the example, some things are not clear to me. I would not want to abuse of your patience, but you could tell me:
1. What does the first "0" stand for?
2. What should the empty square brackets on the last line contain?
3. What does the "5000" stand for? Would that be the milliseconds of the timeout?
Also I have other questions:
4. Wanting to simplify my life, thus deciding not to make a second notification appear, but simply by making the first one disappear, what would be the command to insert at the end of my script?
5. How is the syntax to insert the icon in the case of gdbus?
6. The command I wrote with notify-send allowed me to make this notification appear through a script executed in the background via root (in fact it was preceded by

sudo -u $USER DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$UID/bus

), as I should behave instead in the case of gdbus? I ask because trying it gives me an error.
Exactly what I would like to do is make a notification appear at the beginning of my script and make it disappear when it reaches the end. I can keep it "forever" on the screen by giving it urgency level 2, that is correspond to "critical". This script is a .sh script written in Bash which updates the system (therefore it has root rights) and which is automatically executed daily through a systemd timer.


Arciere

Offline

#6 2021-12-13 16:28:23

seth
Member
Registered: 2012-09-03
Posts: 29,723

Re: notify-send

1. Generic/invalid/unused cookie uid
2. https://specifications.freedesktop.org/ … 01s09.html ("actions") - nothing
3. Yes
4. You make a second notification appear that replaces the first one but only lives for a milisecond. There's no API to just withdraw notifications.
5. I've no idea (not a huge fan of icons…), but I guess just the path to the png.
6. "I ask because trying it gives me an error." - https://bbs.archlinux.org/viewtopic.php?id=57855

Offline

Board footer

Powered by FluxBB