Created
September 15, 2020 15:35
-
-
Save kjetilho/d3d6da041d9bfea8457e9d72de3c6cdd to your computer and use it in GitHub Desktop.
a script to adjust volume. it will try to use the most recent audio card by default.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
case $1 in | |
-c) | |
card=$2; shift; shift;; | |
*) | |
card=$(awk '/digital audio playback/ {c = substr($0, 7, 2)} END {print c}' /proc/asound/devices) | |
;; | |
esac | |
if [ $# -eq 2 ] | |
then | |
channel="$1"; shift | |
else | |
# get name of simple mixers with p(layback) volume | |
channels=($(amixer -c $card scontents | | |
awk 'BEGIN{RS="Simple mixer control "} /pvolume/ {print $1}' | | |
cut -d, -f1)) | |
# without an index, an array variable expands to first element | |
channel=$channels | |
fi | |
if [ $# != 1 ] | |
then | |
cat <<EOF >&2 | |
Usage: $0 [-c CARD] [<channel>] <adjustment> | |
Examples: | |
volume_adjust toggle -- toggles mute on/off | |
volume_adjust 5%+ -- increase volume by 5% | |
EOF | |
printf "Available controls for card %d: %s\n" $card "${channels[*]}" | |
exit 64 | |
fi | |
case $1 in | |
[0-9]*) | |
amixer -c $card set $channel $1 >/dev/null ;; | |
mute|unmute|toggle) | |
pasink=($(pacmd list-sinks | awk '/[*] index:/ {i=$3} i && /muted:/ {print i, $2; exit}')) | |
case "$1:${pasink[1]}" in | |
mute:*) mute=true ;; | |
unmute:*) mute=false ;; | |
toggle:yes) mute=false ;; | |
toggle:no) mute=true ;; | |
*) echo "wha? [$1] [${pasink[@]}]"; exit 1 ;; | |
esac | |
pacmd set-sink-mute ${pasink[0]} $mute | |
esac | |
pkill -USR1 -x i3status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment