
rrob
By: a guest on Jan 12th, 2010 | syntax:
Bash | size: 0.80 KB | hits: 224 | expires: Never
#/bin/bash
# Pulse Audio Sound Card Switcher v1,0 2010-01-13
# Switch default sound card in pulseaudio to next one presented in system. Actual audio streams will not be forwarded.
totalsc=$(pacmd "list-sinks" | grep card: | wc -l) # total of sound cards: $totalsc
if [ $totalsc -le 1 ]; then echo "Nothing to switch, system have only one sound card." ; exit ; fi # Check if is present more then one sound card.
scindex=$(pacmd list-sinks | awk '$1 == "*" && $2 == "index:" {print $3}') # index of default sound card: $scindex
nextsc=$(( (scindex+1)%$totalsc )) # index of next sound card: $nextsc
pacmd "set-default-sink $nextsc" > /dev/null # switch default sound card to next one
# CC BY - creative commons
# Thanks God for help :) and guys lhunath, geirha, Tramp and others from irc #bash on freenode.net