~/.local/bin/notification
#!/bin/bash
#
# by nietz
function music {
MUSIC_DIR="$HOME/Music/"
ICON="$MUSIC_DIR/cover.png"
while true; do
mpc idleloop |
while read update; do
#pkill dunst
#killall -SIGUSR1 dunst # pause
#killall -SIGUSR2 dunst # resume
if [ $update == "player" ]; then
#pkill dunst
#nohup dunst > /dev/null 2&1
ffmpeg -i "$MUSIC_DIR/`mpc current -f '%file%'`" -vf scale=100:-1 \
-codec png -y $ICON >/dev/null 2>&1;
# Get fields from mpc, split by tabs.
IFS=$'\t' read album artist title \
<<< "$(mpc --format="%album%\t%artist%\t%title%")"
notify-send --urgency=normal --expire-time=5000 --app-name=mpd \
--icon=$ICON " $title" " by $artist"
#notify-send --urgency=low --expire-time=5000 --app-name=mpd \
# --icon=/home/nietz/Music/cover.png "$title" "$artist\n$album"
elif [ $update == "mixer" ]; then
# Get volume
vol=`mpc | tail -n1 | awk '{print $2}'`
#vol=`mpc | sed -n 3p | awk '{print $1 " " $2}'`
#vol=`mpc | sed -n 3p | cut -d '%' -f 1 | cut -d ' ' -f 2`
notify-send --urgency=low --expire-time=1000 --app-name=mpd \
--icon=$ICON " Volume: $vol" "Mixer Changed"
fi
# if [[ `mpc | wc -l` == 1 ]]; then
# after=""
# else
# after=`mpc | head -n1 | awk -F "-" '{print $2 " - " $1 }'`
# if [[ $before != $after ]]; then
# notify-send $after
# fi
# fi
# before=$after
done
done
}
case $1 in
music) music ;;
*) exit 1 ;;
esac