Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function set_default_playback_device_next {
- # this number is useful when we are on the last soundcard:
- # if it can't find a next soundcard, it will try to find previous one
- inc=${1:-1}
- # how many devices do we have ?
- num_devices=$(pacmd list-sinks | grep -c index:)
- # make a list of devices numbers we found (the lines starting with index:)
- sink_arr=($(pacmd list-sinks | grep index: | grep -o '[0-9]\+'))
- # find which device is the currently active one
- default_sink_index=$(( $(pacmd list-sinks | grep index: | grep -no '*' | grep -o '^[0-9]\+') - 1 ))
- # remainder of the euclidian division : current device number + number of devices + 1 / number of devices
- # = next device , or = first device if we were using the last one
- default_sink_index=$(( ($default_sink_index + $num_devices + $inc) % $num_devices ))
- default_sink=${sink_arr[$default_sink_index]}
- # move the output
- pacmd set-default-sink $default_sink
- # move the inputs related to outputs
- move_sinks_to_new_default $default_sink
- }
- function move_sinks_to_new_default {
- DEFAULT_SINK=$1
- pacmd list-sink-inputs | grep index: | grep -o '[0-9]\+' | while read SINK
- do
- pacmd move-sink-input $SINK $DEFAULT_SINK
- done
- }
- set_default_playback_device_next
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement