Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- headphones="usb-Burr-Brown"
- headset="hdmi-stereo-extra2"
- headphonesMic="input.usb-Burr-Brown"
- headsetMic="Valve_VR_Radio"
- currentSink="$(pacmd list-sinks | grep '*' | awk '{print $3;}')"
- headsetSink="$(pactl list short sinks | grep $headset | awk '{print $1;}')"
- headphonesSink="$(pactl list short sinks | grep $headphones | awk '{print $1;}')"
- currentSource="$(pacmd list-sources | grep '*' | awk '{print $3;}')"
- headsetSource="$(pactl list short sources | grep $headsetMic | awk '{print $1;}')"
- headphonesSource="$(pactl list short sources | grep $headphonesMic | awk '{print $1;}')"
- if [ -z "$1" ]; then
- echo "Autoswitching sound output and input"
- if [ "$currentSink" = "$headphonesSink" ]; then
- echo "Switching to VR headset"
- targetSink="$headsetSink"
- targetSource="$headsetSource"
- else
- echo "Switching to headphones"
- targetSink="$headphonesSink"
- targetSource="$headphonesSource"
- fi
- else
- if [ "$1" = "vr" ] || [ "$1" = "1" ]; then
- echo "Switching to VR headset"
- targetSink="$headsetSink"
- targetSource="$headsetSource"
- elif [ "$1" = "headphones" ] || [ "$1" = "0" ]; then
- echo "Switching to headphones"
- targetSink="$headphonesSink"
- targetSource="$headphonesSource"
- elif [ "$1" = "status" ]; then
- if [ "$currentSink" = "$headphonesSink" ]; then
- echo "Currently using headphones"
- exit 0
- elif [ "$currentSink" = "$headsetSink" ]; then
- echo "Currently using VR headset"
- exit 1
- else
- echo "Currently using unknown device ($currentSink)"
- exit -1
- fi
- fi
- fi
- pacmd set-default-sink "$targetSink"
- pacmd set-default-source "$targetSource"
- pactl list short sink-inputs|while read stream; do
- streamId=$(echo $stream|cut '-d ' -f1)
- pactl move-sink-input "$streamId" "$targetSink"
- done
- pactl list short source-outputs|while read stream; do
- streamId=$(echo $stream|cut '-d ' -f1)
- pactl move-source-output "$streamId" "$targetSource" 2> /dev/null
- done
- echo "Done!"
Advertisement
Add Comment
Please, Sign In to add comment