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:
- # sudo gedit /usr/local/bin/audio-device-switch.sh
- copy , paste source code bellow in gedit editor
- save , close gedit
- # sudo chmod 755 /usr/local/bin/audio-device-switch.sh
- system -> preferences -> keyboard shortcuts
- press „add“ , enter „switch between audio devices“ name , audio-device-switch.sh command , press „apply“.
- select newly added shortcut row , click on „shortcut“ column. choose shortcut combination – e.g. win + f12.
- that's - can plug in plug in hdmi device , switch audio output pressing chosen shortcut combination.
hope helpful.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;
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
Post a Comment