Pulseaudio switch audio device


/ Published in: Bash
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. #!/bin/bash
  2. #
  3. # Sound output switcher using PulseAudio,libnotify
  4. #
  5. # by Mickaël Quirin <eephyne[guess what put here]gmail.com
  6. # inspired by script done by Anton Veretenenko <anton[email sign]veretenenko.ru>
  7.  
  8. notify_show=1
  9. notify_delay=2000
  10. hdmi_card_num=0
  11.  
  12.  
  13. active_device=`pacmd list-sinks | grep -i -E '\* index' | sed -r "s/^.*\* index: //"`
  14.  
  15. if [ "$active_device" == "$hdmi_card_num" ]
  16. then
  17. pacmd "set-default-sink 1"
  18. test=`pacmd list-sink-inputs | grep -i -E 'index:'`
  19.  
  20. while read -r line;
  21. do
  22. sink=(`echo $line | sed -r s/^.*index:\ //`)
  23. pacmd move-sink-input $sink 1;
  24. done <<< $test
  25.  
  26. if [ $notify_show -eq 1 ]
  27. then
  28. notify-send -u normal -t $notify_delay -i gnome-sound-properties "HDMI Off" "Sound output switched to internal audio"
  29. fi
  30. else
  31.  
  32. pacmd "set-default-sink 0"
  33. test=`pacmd list-sink-inputs | grep -i -E 'index:'`
  34.  
  35. while read -r line;
  36. do
  37. sink=(`echo $line | sed -r s/^.*index:\ //`)
  38. pacmd move-sink-input $sink 0;
  39. done <<< $test
  40.  
  41. if [ $notify_show -eq 1 ]
  42. then
  43. notify-send -u normal -t $notify_delay -i gnome-sound-properties "HDMI On" "Sound output switched to HDMI output"
  44. fi
  45. fi

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.