Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- headphonesIndex=$(pacmd list-sinks | grep -v "usb" | grep -B 1 "name:" | tr -d "[[:space:]]" | cut -c 7)
- speakerIndex=$(pacmd list-sinks | grep -v "pci" | grep -B 1 "name:" | tr -d "[[:space:]]" | cut -c 7)
- if [ "$1" = "-headphones" ]; then
- newOutput="headphones"
- newOutputIndex=$headphonesIndex
- elif [ "$1" = "-speaker" ]; then
- newOutputIndex=$speakerIndex
- else
- echo "Invalid argument. Valid arguments are \"-headphones\" and \"-speaker\"."
- exit
- fi
- playbackStreams=$(pacmd list-sink-inputs | grep "index" | cut -c 12-)
- readarray -t playbackStreams <<<"$playbackStreams"
- if [ "$playbackStreams" = "" ]; then
- pacmd set-default-sink $newOutputIndex
- else
- for stream in "${playbackStreams[@]}"
- do
- pacmd move-sink-input $stream $newOutputIndex
- done
- pacmd set-default-sink $newOutputIndex
- fi
Add Comment
Please, Sign In to add comment