Files
2026-09-14 12:43:38 +02:00

26 lines
590 B
Bash
Executable File

#!/bin/bash
# Send a notification message to all active graphical user sessions
# Usage: sudo ./notify_all_gui_users.sh "Your message here"
if [ -z "$1" ]; then
echo "Usage: $0 \"message\""
exit 1
fi
MESSAGE="$1"
loginctl list-sessions --no-legend | while read -r session uid user seat tty; do
# Only graphical sessions
if [[ "$seat" == seat* ]]; then
BUS="/run/user/$uid/bus"
if [[ -S "$BUS" ]]; then
echo XNotify $user $uid $MESSAGE
sudo -u "$user" \
DBUS_SESSION_BUS_ADDRESS="unix:path=$BUS" \
notify-send "$MESSAGE"
fi
fi
done