dunst-volume-indicator.sh 916 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. # changeVolume
  4. # Arbitrary but unique message id
  5. msgId="991049"
  6. # Change the volume using alsa(might differ if you use pulseaudio)
  7. amixer -c 0 set Master "$@" > /dev/null
  8. # Query amixer for the current volume and whether or not the speaker is muted
  9. volume="$(amixer -c 0 get Master | tail -1 | awk '{print $4}' | sed 's/[^0-9]*//g')"
  10. mute="$(amixer -c 0 get Master | tail -1 | awk '{print $6}' | sed 's/[^a-z]*//g')"
  11. if [[ $volume == 0 || "$mute" == "off" ]]; then
  12. # Show the sound muted notification
  13. dunstify -a "changeVolume" -u low -i audio-volume-muted -r "$msgId" "Volume muted"
  14. else
  15. # Show the volume notification
  16. dunstify -a "changeVolume" -u low -i audio-volume-high -r "$msgId" \
  17. -h int:value:"$volume" "Volume: ${volume}%"
  18. fi
  19. # # Play the volume changed sound
  20. # canberra-gtk-play -i audio-volume-change -d "changeVolume"