Skip to content

Instantly share code, notes, and snippets.

@Bonno
Created September 14, 2018 11:28
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 Bonno/7bc048bb5f8f3493ea99b86abd4dde8e to your computer and use it in GitHub Desktop.
Save Bonno/7bc048bb5f8f3493ea99b86abd4dde8e to your computer and use it in GitHub Desktop.
Send notification to all x users with notify-send
users=$(who | grep -iv pts | awk '{print $1}')
for user in $users
do
echo $user
pgrep "gnome-session" -u $user | while read -r line; do
#exp=$(cat /proc/$line/environ | grep -z "^DBUS_SESSION_BUS_ADDRESS=")
exp=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$line/environ | tr '\0' '\n')
echo export "$exp" > /tmp/exports.sh
break
done
if [[ -f /tmp/exports.sh ]]; then
source /tmp/exports.sh
export DBUS_SESSION_BUS_ADDRESS
export DISPLAY=$d
su $user -c "/usr/bin/notify-send 'Hi!' 'test'"
rm /tmp/exports.sh
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment