Advertisement
alienjon

Toggle Pulseaudio Outputs

Aug 20th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.36 KB | None | 0 0
  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. # Modified by alienjon <holy.smoking.floorboards.batman[ ]gmail.com>
  9.    
  10. notify_show=1
  11. notify_delay=2000
  12. headset_card_num=1
  13. stereo_card_num=2
  14.    
  15.    
  16. active_device=`pacmd list-sinks | grep -i -E '\* index' | sed -r "s/^.*\* index: //"`
  17.    
  18. if [ "$active_device" == "$headset_card_num" ]
  19. then
  20. pacmd "set-default-sink ${stereo_card_num}"
  21. test=`pacmd list-sink-inputs | grep -i -E 'index:'`
  22.    
  23. while read -r line;
  24. do
  25. sink=(`echo $line | sed -r s/^.*index:\ //`)
  26. pacmd move-sink-input $sink ${stereo_card_num};
  27. done <<< $test
  28.    
  29.     if [ $notify_show -eq 1 ]
  30.     then
  31.     notify-send -u normal -t $notify_delay -i gnome-sound-properties "Speakers Enabled" "Sound output switched to speakers"
  32.     fi
  33. else
  34.    
  35.     pacmd "set-default-sink ${headset_card_num}"
  36. test=`pacmd list-sink-inputs | grep -i -E 'index:'`
  37.    
  38. while read -r line;
  39. do
  40. sink=(`echo $line | sed -r s/^.*index:\ //`)
  41. pacmd move-sink-input $sink ${headset_card_num};
  42. done <<< $test
  43.    
  44.     if [ $notify_show -eq 1 ]
  45.     then
  46.     notify-send -u normal -t $notify_delay -i gnome-sound-properties "Headset Enabled" "Sound output switched to headsets"
  47.     fi
  48. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement