I found the script finally. This script will move all input sinks (i.e. your music, video sound etc.) to your other sound device. If you run the script again it will move all sinks back to your original sound device. (I have only tested this on two sound devices).
Instruction on how to setup:
- Paste the following code into a file using gedit.
- Save the file as speakers.sh (or some other file name) in your home directory.
Change the file permissions to allow execution.
- Right click the file and choose properties.
- Select the permissions tab.
- Tick the "Allow executing file as program" tick box
or
Double click the file and click run. It will change the output sound device.
I then added an option on the settings icon in the unity launcher for ease of access using Ubuntu Tweak. Enjoy!
Code:
#!/bin/bash
declare -i sinks=(`pacmd list-sinks | sed -n -e 's/\**[[:space:]]index:[[:space:]]\([[:digit:]]\)/\1/p'`)
declare -i sinks_count=${#sinks[*]}
declare -i active_sink_index=`pacmd list-sinks | sed -n -e 's/\*[[:space:]]index:[[:space:]]\([[:digit:]]\)/\1/p'`
declare -i next_sink_index=${sinks[0]}
#find the next sink (not always the next index number)
declare -i ord=0
while [ $ord -lt $sinks_count ];
do
echo ${sinks[$ord]}
if [ ${sinks[$ord]} -gt $active_sink_index ] ; then
next_sink_index=${sinks[$ord]}
break
fi
let ord++
done
#change the default sink
pacmd "set-default-sink ${next_sink_index}"
#move all inputs to the new sink
for app in $(pacmd list-sink-inputs | sed -n -e 's/index:[[:space:]]\([[:digit:]]\)/\1/p');
do
pacmd "move-sink-input $app $next_sink_index"
done
#display notification
declare -i ndx=0
pacmd list-sinks | sed -n -e 's/device.description[[:space:]]=[[:space:]]"\(.*\)"/\1/p' | while read line;
do
if [ $(( $ord % $sinks_count )) -eq $ndx ] ; then
notify-send -i notification-audio-volume-high --hint=string:x-canonical-private- synchronous: "Sound output switched to" "$line"
exit
fi
let ndx++
done;
All credit goes to the guys here, I just re-found the answer to my question.