Skip to content

Instantly share code, notes, and snippets.

@NishargShah
Last active January 10, 2022 11:18
Show Gist options
  • Save NishargShah/160915aae5278e2448a87767ce225f9c to your computer and use it in GitHub Desktop.
Save NishargShah/160915aae5278e2448a87767ce225f9c to your computer and use it in GitHub Desktop.
Help to toggle sound device
#!/bin/bash
SINK=$(pacmd list-sinks | grep index)
INDEX_1=${SINK:11:2}
SINK=$(pacmd list-sinks | grep index | grep -vw "index: 1")
INDEX_2=${SINK:11:2}
SINK=$(pacmd list-sinks | grep "* index")
ACTIVE_SINK=${SINK:11:2}
if [ $ACTIVE_SINK = $INDEX_2 ]; then
echo Setting Speaker
pacmd set-default-sink $INDEX_1
elif [ $ACTIVE_SINK = $INDEX_1 ]; then
echo Setting Headphone
pacmd set-default-sink $INDEX_2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment