Guest User

Linux VR Audio Switcher by pierogo/makisekuritorisu

a guest
Apr 14th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.95 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. headphones="usb-Burr-Brown"
  4. headset="hdmi-stereo-extra2"
  5.  
  6. headphonesMic="input.usb-Burr-Brown"
  7. headsetMic="Valve_VR_Radio"
  8.  
  9. currentSink="$(pacmd list-sinks | grep '*' | awk '{print $3;}')"
  10. headsetSink="$(pactl list short sinks | grep $headset | awk '{print $1;}')"
  11. headphonesSink="$(pactl list short sinks | grep $headphones | awk '{print $1;}')"
  12.  
  13. currentSource="$(pacmd list-sources | grep '*' | awk '{print $3;}')"
  14. headsetSource="$(pactl list short sources | grep $headsetMic | awk '{print $1;}')"
  15. headphonesSource="$(pactl list short sources | grep $headphonesMic | awk '{print $1;}')"
  16.  
  17. if [ -z "$1" ]; then
  18.     echo "Autoswitching sound output and input"
  19.     if [ "$currentSink" = "$headphonesSink" ]; then
  20.         echo "Switching to VR headset"
  21.         targetSink="$headsetSink"
  22.         targetSource="$headsetSource"
  23.     else
  24.         echo "Switching to headphones"
  25.         targetSink="$headphonesSink"
  26.         targetSource="$headphonesSource"
  27.     fi
  28. else
  29.     if [ "$1" = "vr" ] || [ "$1" = "1" ]; then
  30.         echo "Switching to VR headset"
  31.         targetSink="$headsetSink"
  32.         targetSource="$headsetSource"
  33.     elif [ "$1" = "headphones" ] || [ "$1" = "0" ]; then
  34.         echo "Switching to headphones"
  35.         targetSink="$headphonesSink"
  36.         targetSource="$headphonesSource"
  37.     elif [ "$1" = "status" ]; then
  38.         if [ "$currentSink" = "$headphonesSink" ]; then
  39.             echo "Currently using headphones"
  40.             exit 0
  41.         elif [ "$currentSink" = "$headsetSink" ]; then
  42.             echo "Currently using VR headset"
  43.             exit 1
  44.         else
  45.             echo "Currently using unknown device ($currentSink)"
  46.             exit -1
  47.         fi
  48.     fi
  49. fi
  50.  
  51. pacmd set-default-sink "$targetSink"
  52. pacmd set-default-source "$targetSource"
  53.  
  54. pactl list short sink-inputs|while read stream; do
  55.     streamId=$(echo $stream|cut '-d ' -f1)
  56.     pactl move-sink-input "$streamId" "$targetSink"
  57. done
  58.  
  59. pactl list short source-outputs|while read stream; do
  60.     streamId=$(echo $stream|cut '-d ' -f1)
  61.     pactl move-source-output "$streamId" "$targetSource" 2> /dev/null
  62. done
  63.  
  64. echo "Done!"
Advertisement
Add Comment
Please, Sign In to add comment