notify-send "Header" "Content" --icon network-idle
su -l user -c 'notify-send "Header" "Content" --icon network-idle'
I’m using the latest updated Qubes OS 4.1 release. Neither of these commands work when called in /rw/config/rc.local or /rw/config/qubes-firewall-user-script.
Please advise.
To get notification from (fedora) app qubes, install notification-daemon and libnotify (already installed).
Just tested fom fresh fedora 37 minimal template.
szz9pza said it doesn’t start because dbus isn’t ready.
You can wait and see if it becomes available, but you probably need to set up the dbus address variable.
You can also make an .desktop file in /home/user/.config/autostart and use that file to execute your shell script, that is what I normally do when I need to run something that requires xorg to be up and running.
notify-send is installed and fully functional in fedora 37.
There must be an error in that script in calling it, rather than
anything else.
As user, can you confirm this with notify-send 'test' 'test'
Post the section of the script you have commented out, and how you are
calling the script.
I never presume to speak for the Qubes team.
When I comment in the Forum or in the mailing lists I speak for myself.
I figured out a solution to using notify-send as any user. Essentially I had to install dbus-x11 to perform dbus-launch and add a notification service for dbus so notifications could be sent properly.
The following steps work for Fedora 38. It should also work for Debian systems.
Install dbus-x11 in template
sudo dnf install dbus-x11
Copy the following into /usr/share/dbus-1/services/org.freedesktop.Notifications.service
It should be noted this assumes you’re using xfce4 in dom0. If you are not see which notification service you are using by doing ps aux | grep notify and replacing that in the exec.
The script below is for notification of Wireguard connections via the preup, postup, predown, and postdown hooks in the Wireguard configuration.
Every time dbus-launch executes it creates a new session so we store it in a temporary file and reuse it.
#!/bin/bash
# Hostname of vm
HOSTNAME="$(hostname)"
# Wireguard config file
WIREGUARD_CONFIG="/etc/wireguard/wg0.conf"
# File to store dbus session
DBUS_INFO_FILE="/tmp/wireguard_dbus_session_info"
# Function to send notification with a timeout
send_notification() {
local start_time=$(date +%s)
local timeout=30
local success=0
# Set the DISPLAY environment variable
export DISPLAY=:0
# If DBUS_SESSION_BUS_ADDRESS isn't set, try to source from file or launch a new one
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
if [ -f "$DBUS_INFO_FILE" ]; then
source "$DBUS_INFO_FILE"
fi
# Check if D-Bus is still running
if ! pgrep -f "dbus-daemon --fork --print-address 5 --print-pid 6" > /dev/null; then
eval $(/usr/bin/dbus-launch --sh-syntax) > "$DBUS_INFO_FILE"
fi
fi
# Try to send the notification until it succeeds or timeout
while [[ $(( $(date +%s) - $start_time )) -lt $timeout ]]; do
# Attempt to send the notification
/usr/bin/notify-send "$@" && {
success=1
break
}
sleep 1
done
if [[ $success -eq 0 ]]; then
echo "Failed to send notification after 30 seconds."
# Exit with code 0 to not fail wg-quick service
exit
fi
}
ENDPOINT=$(grep "Endpoint" $WIREGUARD_CONFIG | cut -d '=' -f 2 | cut -d ':' -f 1)
# Handling wireguard notification hooks
case $1 in
preup)
send_notification "Wireguard: $HOSTNAME" "Connecting to $ENDPOINT..."
;;
postup)
send_notification "Wireguard: $HOSTNAME" "Connected to $ENDPOINT!"
;;
predown)
send_notification "Wireguard: $HOSTNAME" "Disconnecting from $ENDPOINT..."
;;
postdown)
send_notification "Wireguard: $HOSTNAME" "Disconnected from $ENDPOINT!"
;;
*)
echo "Invalid argument. Use preup, postup, predown, or postdown."
exit 1
;;
esac