Skip to main content

Thread: Audio device switch


i have system graphic card hdmi output , i'm using tv watch movies , listen music though hdmi. unfortunately ubuntu doesn't switch sound output automatically upon hdmi device connection , had manually everytime. after research , experiments made little bash script switches output audio devices.

script assumes pulseaudio used , tested karmic. pretty generic , has nothing hdmi device – iterates on sound devices , switches output next one.

here how make work:
  1. # sudo gedit /usr/local/bin/audio-device-switch.sh
  2. copy , paste source code bellow in gedit editor
  3. save , close gedit
  4. # sudo chmod 755 /usr/local/bin/audio-device-switch.sh
  5. system -> preferences -> keyboard shortcuts
  6. press „add“ , enter „switch between audio devices“ name , audio-device-switch.sh command , press „apply“.
  7. select newly added shortcut row , click on „shortcut“ column. choose shortcut combination – e.g. win + f12.
  8. that's - can plug in plug in hdmi device , switch audio output pressing chosen shortcut combination.

code:
#!/bin/bash    declare -i sinks_count=`pacmd list-sinks | grep -c index:[[:space:]][[:digit:]]`  declare -i active_sink_index=`pacmd list-sinks | sed -n -e 's/\*[[:space:]]index:[[:space:]]\([[:digit:]]\)/\1/p'`  declare -i major_sink_index=$sinks_count-1  declare -i next_sink_index=0    if [ $active_sink_index -ne $major_sink_index ] ;  	next_sink_index=active_sink_index+1  fi    #change default sink  pacmd "set-default-sink ${next_sink_index}"    #move inputs new sink  app in $(pacmd list-sink-inputs | sed -n -e 's/index:[[:space:]]\([[:digit:]]\)/\1/p');   	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;   	if [ $next_sink_index -eq $ndx ] ;  		notify-send -i notification-audio-volume-high "sound output switched to" "$line"  		exit  	fi  	ndx+=1  done;
hope helpful.

hi,
looking for. have desktop-starter linked script, , can move audio 1 click. looking


Forum The Ubuntu Forum Community Ubuntu Official Flavours Support Hardware Audio device switch


Ubuntu

Comments

Popular posts from this blog

sd card Could not find FAT16/FAT32 partition [solved]

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Programming ATtiny816 using Arduino IDE