Return to Snippet

Revision: 62929
at March 24, 2013 21:14 by eephyne


Updated Code
#!/bin/bash
#
# Sound output switcher using PulseAudio,libnotify
#
# by Mickaël Quirin <eephyne[guess what put here]gmail.com
# inspired by script done by Anton Veretenenko <anton[email sign]veretenenko.ru>

notify_show=1
notify_delay=2000
hdmi_card_num=0


active_device=`pacmd list-sinks | grep -i -E '\* index' | sed -r "s/^.*\* index: //"`

if [ "$active_device" == "$hdmi_card_num" ]
then
pacmd "set-default-sink 1"
test=`pacmd list-sink-inputs | grep -i -E 'index:'`

while read -r line; 
do 
sink=(`echo $line | sed -r s/^.*index:\ //`)
pacmd move-sink-input $sink 1; 
done <<< $test

 if [ $notify_show -eq 1 ]
 then
  notify-send -u normal -t $notify_delay -i gnome-sound-properties "HDMI Off" "Sound output switched to internal audio"
 fi
else

 pacmd "set-default-sink 0"
test=`pacmd list-sink-inputs | grep -i -E 'index:'`

while read -r line; 
do 
sink=(`echo $line | sed -r s/^.*index:\ //`)
pacmd move-sink-input $sink 0; 
done <<< $test

 if [ $notify_show -eq 1 ]
 then
  notify-send -u normal -t $notify_delay -i gnome-sound-properties "HDMI On" "Sound output switched to HDMI output"
 fi
fi

Revision: 62928
at March 24, 2013 21:10 by eephyne


Initial Code
#!/bin/bash
#
# Sound output switcher using PulseAudio,libnotify
#
# by Mickaël Quirin <eephyne[guess what put here]gmail.com
# inspired by script done by Anton Veretenenko <anton[email sign]veretenenko.ru>

notify_show=1
notify_delay=2000
hdmi_card_num=0


active_device=`pacmd list-sinks | grep -i -E '\* index' | sed -r "s/^.*\* index: //"`

if [ "$active_device" == "$hdmi_card_num" ]
then
pacmd "set-default-sink 1"
test=`pacmd list-sink-inputs | grep -i -E 'index:'`

while read -r line; 
do 
sink=(`echo $line | sed -r s/^.*index:\ //`)
pacmd move-sink-input $sink 1; 
done <<< $test

 if [ $notify_show -eq 1 ]
 then
  notify-send -u normal -t $notify_delay -i gnome-sound-properties "HDMI Off" "Sound output switched to internal audio"
 fi
else

 pacmd "set-default-sink 0"
test=`pacmd list-sink-inputs | grep -i -E 'index:'`

while read -r line; 
do 
sink=(`echo $line | sed -r s/^.*index:\ //`)
pacmd move-sink-input $sink 0; 
done <<< $test

 if [ $notify_show -eq 1 ]
 then
  notify-send -u normal -t $notify_delay -i gnome-sound-properties "HDMI On" "Sound output switched to HDMI output"
 fi
fi

Initial URL

                                

Initial Description
This script is mean to be associated with a keyboard shortcut , his purpose is to switch from internal output to hdmi output. It also switch output for all source (meaning all software currently outputing sound).

you can modify :
notify_show : 1 to show , 0 to not show
notify_delay : the time to show the notification in ms
hdmi_card_num : the number of your hdmi card , this can be found using "pacmd list-sinks" and looking to the index number corresponding to the hdmi sink

Initial Title
Pulseaudio switch audio device

Initial Tags

                                

Initial Language
Bash