Skip to content

Instantly share code, notes, and snippets.

@hroncok
Last active October 31, 2024 10:23
Show Gist options
  • Save hroncok/4478690 to your computer and use it in GitHub Desktop.
Save hroncok/4478690 to your computer and use it in GitHub Desktop.
PulseAudio volume command for key shortcuts
#!/usr/bin/env bash
export LANG=C.utf-8
SPEAKERS=alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__Speaker__sink
MIC=alsa_input.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__Mic1__source
if [[ $1 == "+" ]]; then
# pacmd dump|awk --non-decimal-data '$1~/set-sink-volume/{system ("pacmd "$1" "$2" "$3+2000)}' > /dev/null
volume=$(pactl get-sink-volume $SPEAKERS | head -n1 | cut -f3 -d' ')
pactl set-sink-volume $SPEAKERS $(($volume+2000))
elif [[ $1 == "-" ]]; then
# pacmd dump|awk --non-decimal-data '$1~/set-sink-volume/{system ("pacmd "$1" "$2" "$3-2000)}' > /dev/null
volume=$(pactl get-sink-volume $SPEAKERS | head -n1 | cut -f3 -d' ')
pactl set-sink-volume $SPEAKERS $(($volume-2000))
elif [[ $1 == "mute" ]]; then
# pacmd dump|awk --non-decimal-data '$1~/set-sink-mute/{system ("pacmd "$1" "$2" "($3 == "yes"?"no":"yes"))}' > /dev/null
if [[ "$(pactl get-sink-mute $SPEAKERS)" == "Mute: no" ]]; then
pactl set-sink-mute $SPEAKERS yes
else
pactl set-sink-mute $SPEAKERS no
fi
elif [[ $1 == "mutemic" ]]; then
#pacmd dump|awk --non-decimal-data '$1~/set-source-mute/{system ("pacmd "$1" "$2" "($3 == "yes"?"no":"yes"))}' > /dev/null
if [[ "$(pactl get-source-mute $MIC)" == "Mute: no" ]]; then
pactl set-source-mute $MIC yes
else
pactl set-source-mute $MIC no
fi
else
echo "Usage: volume [+|-|mute|mutemic]"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment