pactl-volume (1657B)
1 #!/usr/bin/env bash 2 SINK=$(pactl list sinks short | tail -n 1 | grep -o '^[0-9]') 3 if [ "$1" = "up" ]; then 4 /usr/bin/pactl set-sink-mute "$SINK" 0 5 NOW=$( pactl list sinks | grep "^Sink #$SINK" -B 0 -A 999 | grep '^[[:space:]]Volume:' | tail -n $(( $SINK + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,' ) 6 if [ $((NOW+5)) -le 100 ]; then 7 /usr/bin/pactl set-sink-volume "$SINK" "+5%" 8 else 9 /usr/bin/pactl set-sink-volume "$SINK" "100%" 10 fi 11 elif [ "$1" = "down" ]; then 12 NOW=$( pactl list sinks | grep "^Sink #$SINK" -B 0 -A 999 | grep '^[[:space:]]Volume:' | tail -n $(( $SINK + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,' ) 13 if [ $((NOW-5)) -gt 0 ]; then 14 /usr/bin/pactl set-sink-volume "$SINK" "-5%" 15 else 16 /usr/bin/pactl set-sink-volume "$SINK" "0%" 17 /usr/bin/pactl set-sink-mute "$SINK" 1 18 fi 19 elif [ "$1" = "mute" ]; then 20 /usr/bin/pactl set-sink-mute "$SINK" toggle 21 elif [ "$1" = "now" ]; then 22 SINK_INFO=$(pactl list sinks | grep "^Sink #$SINK" -B 0 -A 999) 23 muted=$(echo "$SINK_INFO" | grep Mute | cut -d':' -f2 | tr -d ' ') 24 if [ -z "$(echo "$SINK_INFO" | grep RUNNING)" ]; then 25 NOW=$( echo "$SINK_INFO" | grep '^[[:space:]]Volume:' | tail -n $(( $SINK + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,' ) 26 if [ "$muted" = "no" ]; then 27 echo "NO AUDIO ($NOW%)" 28 else 29 echo "NO AUDIO (MUTE)" 30 fi 31 elif [ "$muted" = "no" ]; then 32 NOW=$( echo "$SINK_INFO" | grep '^[[:space:]]Volume:' | tail -n $(( $SINK + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,' ) 33 echo " $NOW" 34 else 35 echo " muted" 36 fi 37 elif [ "$1" = "sink" ]; then 38 echo "$SINK" 39 fi