mpd-notifyd.sh 928 B

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/sh
  2. state=""
  3. oldstate=""
  4. song=""
  5. oldsong=""
  6. while true ; do
  7. oldstate=$state
  8. oldsong=$song
  9. mpc idle
  10. string=$(mpc status)
  11. if [ "$(echo "$string" | wc -l)" -eq 1 ]; then
  12. if [ "$oldstate" != "stopped" ]; then
  13. dunstify -i media-playback-stopped -a mpd -h string:x-dunst-stack-tag:MPD "Stopped" "$oldsong"
  14. fi
  15. song=""
  16. state="stopped"
  17. elif ! echo "$string" | sed '2!d' | grep -q 'play'; then
  18. song=$(echo "$string" | sed '1!d')
  19. if [ "$song" != "$oldsong" ] || [ "$oldstate" != "playing" ]; then
  20. dunstify -i media-playback-paused -a mpd -h string:x-dunst-stack-tag:MPD "Now Playing:" "$song"
  21. fi
  22. state="playing"
  23. elif ! echo "$string" | sed '2!d' | grep -q 'pause'; then
  24. song=$(echo "$string" | sed '1!d')
  25. if [ "$song" != "$oldsong" ] || [ "$oldstate" != "paused" ]; then
  26. dunstify -i media-playback-playing -a mpd -h string:x-dunst-stack-tag:MPD "Paused" "$song"
  27. fi
  28. state="paused"
  29. fi
  30. done