Skip to content

Instantly share code, notes, and snippets.

@ForeverZer0
Last active January 11, 2025 23:00
Show Gist options
  • Save ForeverZer0/347e888ac7694db78900a3a3ddfb4492 to your computer and use it in GitHub Desktop.
Save ForeverZer0/347e888ac7694db78900a3a3ddfb4492 to your computer and use it in GitHub Desktop.
Simple script to display a notification when the current song changes MPD, showing the title, artist, and cover/album art.
#!/usr/bin/env bash
# Simple script to display display a notification when the current song changes
# in MPD, showing the title, artist, and cover/album art.
#
# Requires: dunst, mpd, and mpc
# Temporary path where album art will be written to.
ALBUMART="/tmp/albumart"
# The number of milliseconds to display the notification
# before automatically closing.
TIMEOUT=3000
song=$(mpc current --format "%file%")
while true
do
current=$(mpc current --format "%file%")
if [ "$song" != "$current" ]; then
song="$current"
mpc albumart "$song" > $ALBUMART
title=$(mpc current --format "%title%")
artist=$(mpc current --format "%artist%")
dunstify -a mpd-notify -u 0 -I "$ALBUMART" -t $TIMEOUT "$title" "$artist"
# Alternatively use notify-send instead of dunstify
# notify-send -a "mpd-notify" -i "$ALBUMART" -t $TIMEOUT "$artist" "$title"
fi
mpc idle player > /dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment