Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # switches the default audio output device for pulse audio, and any applications currently using it to the next available one.
- tmpfile=/tmp/pasink.tmp
- function getNextSink {
- sinks=`pacmd list-sinks |sed 's/*//' |awk '/[*]|index:/{print $2}' >${tmpfile}`
- sink_array=( `cat "${tmpfile}" `)
- tot_sinks=${#sinks_array[@]}
- active_sink=`pacmd list-sinks |awk '/* index:/{print $3}'`
- array_index=${!sink_array[@]}
- for each in ${array_index}
- do
- if [ ${sink_array[$each]} -eq ${active_sink} ]
- then
- active_sink_pos=${each}
- fi
- last_sink_pos=${each}
- done
- count=0
- if [ $active_sink_pos -eq $last_sink_pos ]
- then
- next_sink_pos=0
- else
- let next_sink_pos=${active_sink_pos}+1
- fi
- next_sink=${sink_array[${next_sink_pos}]}
- }
- function getSinkInputs {
- inputs=`pacmd list-sink-inputs |sed 's/*//' |awk '/[*]|index:/{print $2}' >${tmpfile}`
- input_array=`cat $tmpfile`
- }
- function setDefaultSink {
- pacmd set-default-sink ${next_sink} 2>&1 >/dev/null
- }
- function moveSinkInput {
- for each in ${input_array}
- do
- pacmd move-sink-input ${each} ${next_sink} 2>&1 >/dev/null
- done
- }
- case "$*" in
- --get-sink-inputs)
- getSinkInputs
- ;;
- --move-sink-inputs)
- getNextSink
- getSinkInputs
- moveSinkInput
- ;;
- --set-default-sink)
- getNextSink
- setDefaultSink
- ;;
- --next)
- getNextSink
- setDefaultSink
- getSinkInputs
- moveSinkInput
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement