volumectl (1207B)
1 #!/bin/sh 2 3 # Exit with usage. 4 usage() { 5 echo >&2 "usage: volumectl COMMAND ARGS..." 6 echo >&2 7 echo >&2 "Commands:" 8 echo >&2 " up AMOUNT: Adjust output volume up by percentage" 9 echo >&2 " down AMOUNT: Adjust output volume down by percentage" 10 echo >&2 " mute: Toggle output mute" 11 echo >&2 " muteinput: Toggle input mute" 12 } 13 14 adjust_output() { 15 # Check for argument. 16 if [ $# -lt 2 ]; then 17 usage 18 exit 1 19 fi 20 SIGN="$1" 21 PERCENT="$2" 22 if [ "$(uname)" = FreeBSD ]; then 23 mixer -s pcm "${SIGN}${PERCENT}" 24 elif [ "$(uname)" = Linux ]; then 25 pactl set-sink-volume @DEFAULT_SINK@ "${SIGN}${PERCENT}%" 26 fi 27 } 28 29 toggle_mute_output() { 30 if [ "$(uname)" = FreeBSD ]; then 31 mixer -s pcm 0 32 elif [ "$(uname)" = Linux ]; then 33 pactl set-sink-mute @DEFAULT_SINK@ toggle 34 fi 35 } 36 37 toggle_mute_input() { 38 if [ "$(uname)" = Linux ]; then 39 pactl set-source-mute @DEFAULT_SINK@ toggle 40 fi 41 } 42 43 # Check for command. 44 if [ $# -lt 1 ]; then 45 usage 46 exit 1 47 fi 48 49 # No-arg commands. 50 COMMAND="$1" 51 case "$COMMAND" in 52 up) adjust_output + $2 ;; 53 down) adjust_output - $2 ;; 54 mute) toggle_mute_output ;; 55 muteinput) toggle_mute_input ;; 56 *) 57 usage 58 exit 1 59 ;; 60 esac