Using the Ubuntu system, after creating a file /etc/NetworkManager/dispatcher.d/02-upnet that is automatically executed when connecting to the network. In this file, the file /etc/NetworkManager/dispatcher.d/send_notification.sh is invoked:
#!/bin/bash
#export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus
#export DBUS_SESSION_BUS_ADDRESS=unix:path=XDG_RUNTIME_DIR/bus
#if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
# eval $(dbus-launch --sh-syntax --exit-with-session)
#fi
#export DBUS_SESSION_BUS_ADDRESS=$(dbus-launch --autolaunch=$(cat /var/lib/dbus/machine-id) | grep DBUS_SESSION_BUS_ADDRESS | cut -d= -f2-)
#export DISPLAY=:0
exec > /tmp/send_notification.log 2>&1
handle_notification_click() {
echo "BEFORE ACTION"
ACTION=$(dunstify -i /usr/share/icons/Adwaita/32x32/status/security-high-symbolic.symbolic.png
--action="2, Open"
"Notification"
"Click to open"
-t 5000)
echo "ACTION=${ACTION}"
if [ -z "$ACTION" ]; then
echo "User did not interact with the notification."
elif [[ "$ACTION" == *"2"* ]]; then
echo "User clicked the notification."
fi
}
handle_notification_click
pkill dunst
When running ./send_notification.sh manually, the notification appears in the system environment. But when turning on the network, the notification does not appear automatically, as expected. When debugging the errors the following message appears: “Unable to send notification: Cannot autolaunch D-Bus without X11 $DISPLAY”. I’ve already tried inserting export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus
but it appear the error “Unable to send notification: The connection is closed”,and also tried to do autolaunch: export DBUS_SESSION_BUS_ADDRESS=$(dbus-launch --autolaunch=$(cat /var/lib/dbus/machine-id) | grep DBUS_SESSION_BUS_ADDRESS | cut -d= -f2-)
but it gives this error: “Unable to send notification: The given address is empty”.
How do I get to surpass the ” Unable to send notification: Cannot autolaunch D-Bus without X11 $DISPLAY” error and make the dunstify notification appear automatically when turning network on.
Bia Lia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.