#!/bin/bash #notify_xloggedbash kelloco2@gmail.com #Notifies X logged-in users or login manager #Requires libnotify #todo sort -u -k1,1 (if who show duplicates) #example: notify_xloggedbash gpm-battery-100 "Currently using batteries" icon=$1 notification=$2 numxlogged=`who | grep "(:.*)" | wc -l` if [ $numxlogged -ge 1 ]; then for (( n=1; $n <= $numxlogged; n++ )) ; do xlogged=`who | grep "(:.*)" | awk '{ print $5 " " $1 }' | sed -n "$n"p` display=${xlogged:1:2} user=`echo $xlogged | awk '{ print $2 }'` env DISPLAY=$display su $user -c "notify-send -i \"$icon\" \"$notification\"" done else #Uncomment to notify login manager (does not always work, lxdm work, lightdm don't work) #sleep 4 && env DISPLAY=:0 notify-send -i "$icon" "$notification" exit 0 fi