Created
July 16, 2022 10:17
-
-
Save mbaldessari/336de15fc69f9a15b652a89d825a0c50 to your computer and use it in GitHub Desktop.
Toggle pipewire/pulseaudio output or input on/off
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 | |
set -e | |
function error_out() { | |
echo "Error wrong arguments. Pick either input or output" | |
exit 1 | |
} | |
if [ $# -ne 1 ]; then | |
error_out | |
fi | |
TYPE=$1 | |
if [ "${TYPE}" == "input" ]; then | |
SOURCE=$(pactl info | grep "Default Source" | awk '{ print $3; }') | |
MUTED=$(pactl get-source-mute "${SOURCE}" | cut -f2 -d\: | tr "[:upper:]" "[:lower:]") | |
VERB="set-source-mute" | |
elif [ ${TYPE} == "output" ]; then | |
SOURCE=$(pactl info | grep "Default Sink" | awk '{ print $3; }') | |
MUTED=$(pactl get-sink-mute "${SOURCE}" | cut -f2 -d\: | tr "[:upper:]" "[:lower:]") | |
VERB="set-sink-mute" | |
else | |
error_out | |
fi | |
if [ ${MUTED} == "no" ]; then | |
echo "Muting ${TYPE}: ${SOURCE} -> ${MUTED}" | |
pactl "${VERB}" "${SOURCE}" 1 | |
exit 0 | |
elif [ ${MUTED} == "yes" ]; then | |
echo "Unmuting ${TYPE}: ${SOURCE} -> ${MUTED}" | |
pactl "${VERB}" "${SOURCE}" 0 | |
exit 0 | |
fi | |
echo "Error could not parse ${SOURCE} -> ${MUTED}!!" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment