Skip to content

Instantly share code, notes, and snippets.

@jackblk
Last active December 25, 2020 19:59
Show Gist options
  • Save jackblk/bc0a8ddda41e71954b0c1743803eacfb to your computer and use it in GitHub Desktop.
Save jackblk/bc0a8ddda41e71954b0c1743803eacfb to your computer and use it in GitHub Desktop.
Toogle PulseAudio output ports, disable/enable Auto-Mute Mode on Linux
#!/bin/sh
DEVICE='0' # Index/name of the device in `pacmd list-sinks`
CARD='1' # Card index in `cat /proc/asound/cards`
ACTIVE_SINK=$(pacmd list-sinks | grep 'active port' | awk '{ print $3 }')
if [ "$ACTIVE_SINK" = "<analog-output-headphones>" ]; then
echo "[*] Enabling all analog output on $DEVICE."
pacmd set-sink-port "$DEVICE" analog-output-lineout
amixer -c "$CARD" sset 'Auto-Mute Mode' Disabled
else
echo "[*] Enabling headphones only on $DEVICE."
pacmd set-sink-port "$DEVICE" analog-output-headphones
amixer -c "$CARD" sset 'Auto-Mute Mode' Enabled
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment