summaryrefslogtreecommitdiff
path: root/bin/mpd-monitor
diff options
context:
space:
mode:
authorpants <niklasjo2004@gmail.com>2026-09-21 14:17:03 -0700
committerpants <niklasjo2004@gmail.com>2026-09-21 14:17:03 -0700
commit7b21727285e50b0b050c4ddd70d07542229c5366 (patch)
tree5d369153c5df5b41f3750d25479a68f20169c8ff /bin/mpd-monitor
init
Diffstat (limited to 'bin/mpd-monitor')
-rwxr-xr-xbin/mpd-monitor30
1 files changed, 30 insertions, 0 deletions
diff --git a/bin/mpd-monitor b/bin/mpd-monitor
new file mode 100755
index 0000000..009c984
--- /dev/null
+++ b/bin/mpd-monitor
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+PID=$(pgrep -x mpc)
+if [ -n "$PID" ]; then
+ echo "another instance of 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