You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pulsevolumecheck.sh 1.5KB

пре 5 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. #
  3. # pulseaudio-ctl
  4. #
  5. # simple control of pulseaudio vol+/vol-/mute from the shell
  6. # or more practically, from DE shortcut keys
  7. #
  8. # by graysky
  9. # https://github.com/graysky2/pulseaudio-ctl
  10. is_integer() {
  11. if [[ "$1" =~ ^[0-9]+$ ]]; then
  12. echo 1;
  13. else
  14. echo 0;
  15. fi
  16. }
  17. setup() {
  18. SINK=$(pacmd list-sinks|awk '/\* index:/{ print $3 }')
  19. SOURCE=$(pacmd list-sources|awk '/\* index:/{ print $3 }')
  20. PAVERSION=$(pulseaudio --version| sed 's/pulseaudio //')
  21. # this worked some versions of PA 4 but is no longer valid with v5
  22. # CURVOL=$(pacmd list-sinks|grep -A 15 '* index'| awk '/base volume: /{ print $5 }'|sed 's/%//')
  23. CURVOL=$(pacmd list-sinks|grep -A 15 '* index'| awk '/volume: front/{ print $5 }' | sed 's/%//g')
  24. MUTED=$(pacmd list-sinks|grep -A 15 '* index'|awk '/muted:/{ print $2 }')
  25. [[ "$MUTED" = "yes" ]] && MUTED="[m]" ||
  26. MUTED=""
  27. SOURCE_MUTED=$(pacmd list-sources|grep -A 15 '* index'|awk '/muted:/{ print $2 }')
  28. [[ "$SOURCE_MUTED" = "yes" ]] && SOURCE_MUTED="[sm]" ||
  29. SOURCE_MUTED=""
  30. # check that extracted vars are integers
  31. declare -A VARS_TO_CHECK
  32. VARS_TO_CHECK=([SINK]="default sink" [SOURCE]="default source" [CURVOL]="current volume")
  33. for v in "${!VARS_TO_CHECK[@]}"; do
  34. if [[ -n "${!v}" ]]; then
  35. [[ $(is_integer "${!v}") == '1' ]] || echo -e "Cannot determine ${VARS_TO_CHECK[$v]}."
  36. else
  37. return 0
  38. fi
  39. done
  40. }
  41. setup
  42. echo -e "$SOURCE_MUTED$MUTED$CURVOL%"
  43. exit 0
  44. ;;
  45. esac
  46. # vim:set ts=8 sts=2 sw=2 et: