Skip to content

Instantly share code, notes, and snippets.

@TopperBG
Created April 5, 2019 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TopperBG/41449f4ed68cf692774eaabe69216e1f to your computer and use it in GitHub Desktop.
Save TopperBG/41449f4ed68cf692774eaabe69216e1f to your computer and use it in GitHub Desktop.
notify-send to all users
#!/bin/bash
PATH=/usr/bin:/bin
XUSERS=($(who|grep -E "\(:[0-9](\.[0-9])*\)"|awk '{print $1$5}'|sort -u))
for XUSER in $XUSERS; do
NAME=(${XUSER/(/ })
DISPLAY=${NAME[1]/)/}
DBUS_ADDRESS=unix:path=/run/user/$(id -u ${NAME[0]})/bus
sudo -u ${NAME[0]} DISPLAY=${DISPLAY} \
DBUS_SESSION_BUS_ADDRESS=${DBUS_ADDRESS} \
PATH=${PATH} \
notify-send "$@"
done
Copy the above code into a file named "notify-send-all", make it executable and copy it to /usr/local/bin or /usr/bin (as you like). Then run it e.g. as root in a console session like this:
notify-send-all -t 10000 "Warning" "The hovercraft is full of eels!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment