Guest User

audioControl

a guest
May 15th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.86 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. headphonesIndex=$(pacmd list-sinks | grep -v "usb" | grep -B 1 "name:" | tr -d "[[:space:]]" | cut -c 7)
  4. speakerIndex=$(pacmd list-sinks | grep -v "pci" | grep -B 1 "name:" | tr -d "[[:space:]]" | cut -c 7)
  5.  
  6. if [ "$1" = "-headphones" ]; then
  7.     newOutput="headphones"
  8.     newOutputIndex=$headphonesIndex
  9. elif [ "$1" = "-speaker" ]; then
  10.     newOutputIndex=$speakerIndex
  11. else
  12.     echo "Invalid argument. Valid arguments are \"-headphones\" and \"-speaker\"."
  13.     exit
  14. fi
  15.  
  16. playbackStreams=$(pacmd list-sink-inputs | grep "index" | cut -c 12-)
  17. readarray -t playbackStreams <<<"$playbackStreams"
  18.  
  19. if [ "$playbackStreams" = "" ]; then
  20.     pacmd set-default-sink $newOutputIndex
  21. else
  22.     for stream in "${playbackStreams[@]}"
  23.     do
  24.         pacmd move-sink-input $stream $newOutputIndex
  25.     done
  26.     pacmd set-default-sink $newOutputIndex
  27. fi
Add Comment
Please, Sign In to add comment