This thread is a bit old, sorry, but I hope I still can add something useful to the topic. (also Josef Kufner wrote a nice script, it was just a little bit too long for my taste, and it uses PHP).
I also needed a tool as described in the original question (to send a message to all active X-users). And based on the answers here, I wrote this little bash-only script, which searches for active X-users (using who
), and then running notify-send
for every active user.
And the best: you can use my script exactly like "notify-send", with all of its parameters! ;-)
notify-send-all:
#!/bin/bash
PATH=/usr/bin:/bin
XUSERS=($(who|grep -E "(:0-9*)"|awk '{print $1$NF}'|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!"
I'm using it several months now, on different machines, and didn't have any problems so far, and I've tested it with MATE and Cinnamon desktops.
Also successfully running it within cron and anacron.
I wrote this script for/under Arch Linux, so please tell me if you're having problems on another Linux distributions or desktops.