Last active
July 15, 2020 14:43
-
-
Save nitheeshkl/9f42a38d803b52854d03e44bbea020b1 to your computer and use it in GitHub Desktop.
display notifications in linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
user=`whoami` | |
#pids=`pgrep -u $user gnome-panel` | |
pids=`pgrep -u $user wingpanel` | |
title=$1 | |
text=$2 | |
timeout=$3 | |
icon=$4 | |
if [ -z "$title" ]; then | |
echo You need to give me a title >&2 | |
exit 1 | |
fi | |
if [ -z "$text" ]; then | |
text=$title | |
fi | |
if [ -z "$timeout" ]; then | |
timeout=60000 | |
fi | |
for pid in $pids; do | |
# find DBUS session bus for this session | |
DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS \ | |
/proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'` | |
# use it | |
echo $DBUS_SESSION_BUS_ADDRESS | |
#icon hack: | |
if [ -z $icon ]; then | |
DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \ | |
notify-send -u low -t $timeout "$title" "$text" | |
else | |
DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \ | |
notify-send -u low -t $timeout -i "$icon" "$title" "$text" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment