Files
misc/bin/mpd-monitor
2026-01-29 12:15:42 -08:00

38 lines
945 B
Bash
Executable File

#!/bin/sh
# exit if another instance is already running
#if [ !$(pidof mpd-monitor > /dev/null) ]; then
# echo "mpd-monitor already running"
# exit
#fi
# this might actually work...
RUNNING=$(pidof mpc > /dev/null)
if [ !$RUNNING ]; then
echo "mpd-monitor already running"
exit
fi
ID=$(mpc current -f %id% )
mpc idleloop |
while read -r event; do
# if a player event is not output, skip rest of loop
[ "$event" = "player" ] || continue
# get current id to compare to init id
NEW_ID=$(mpc current -f %id%)
# if a player event is output, but the track has not changed, skip rest of loop
[ "$NEW_ID" != "$ID" ] || continue
ID=$NEW_ID
dunstctl close-all
TITLE=$(mpc current -f %title%)
ARTIST=$(mpc current -f %artist%)
if [ -z "$TITLE" ]; then
notify-send "End of queue or queue empty" "or no metadata for track" -i :
else
notify-send "$TITLE" "$ARTIST" -i :
fi
done