It's possible, but not with notify-send
. You need to talk to your desktop notifications service with a less specialized tool, like gdbus
. It will allow you to call various methods from a shell.
An alternative is dbus-send
, but it doesn't (at least for now) support the variant
type needed by the org.freedesktop.Notifications.Notify
method. We will stick to gdbus
.
Check man 1 gdbus
. It includes an example which sends a notification:
gdbus call --session \
--dest org.freedesktop.Notifications \
--object-path /org/freedesktop/Notifications \
--method org.freedesktop.Notifications.Notify \
my_app_name \
42 \
gtk-dialog-info \
"The Summary" \
"Here's the body of the notification" \
[] \
{} \
5000
This should print (uint32 42,)
where 42
is the notification ID. In fact the example specifies 42
explicitly, which means if there already is a notification with this exact ID then it will be replaced. To create a brand new notification specify 0
. A hardcoded ID (like 999
in your question) is possible, but what if the ID is already taken by some unrelated, possibly important notification? For this reason specify 0
, capture the output, isolate the new ID and use it with org.freedesktop.Notifications.CloseNotification
.
Useful links:
Example script:
#!/bin/sh
tty="$(tty)"
id="$(gdbus call --session \
--dest org.freedesktop.Notifications \
--object-path /org/freedesktop/Notifications \
--method org.freedesktop.Notifications.Notify \
my_script \
0 \
utilities-terminal \
"Response required" \
"Script awaiting input ($tty)." \
[] \
{} \
0
)"
id="${id##* }"
id="${id%,)}"
printf 'Type here and hit Enter: '
read foo
>/dev/null gdbus call --session \
--dest org.freedesktop.Notifications \
--object-path /org/freedesktop/Notifications \
--method org.freedesktop.Notifications.CloseNotification \
"$id"