diff --git a/notify_users.sh b/notify_users.sh new file mode 100644 index 0000000..053b589 --- /dev/null +++ b/notify_users.sh @@ -0,0 +1,25 @@ +#!/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 +