Advertisement
Guest User

Untitled

a guest
May 18th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. function set_default_playback_device_next {
  2. # this number is useful when we are on the last soundcard:
  3. # if it can't find a next soundcard, it will try to find previous one
  4. inc=${1:-1}
  5.  
  6. # how many devices do we have ?
  7. num_devices=$(pacmd list-sinks | grep -c index:)
  8.  
  9. # make a list of devices numbers we found (the lines starting with index:)
  10. sink_arr=($(pacmd list-sinks | grep index: | grep -o '[0-9]\+'))
  11.  
  12. # find which device is the currently active one
  13. default_sink_index=$(( $(pacmd list-sinks | grep index: | grep -no '*' | grep -o '^[0-9]\+') - 1 ))
  14.  
  15. # remainder of the euclidian division : current device number + number of devices + 1 / number of devices
  16. # = next device , or = first device if we were using the last one
  17. default_sink_index=$(( ($default_sink_index + $num_devices + $inc) % $num_devices ))
  18.  
  19. default_sink=${sink_arr[$default_sink_index]}
  20.  
  21. # move the output
  22. pacmd set-default-sink $default_sink
  23. # move the inputs related to outputs
  24. move_sinks_to_new_default $default_sink
  25. }
  26.  
  27.  
  28.  
  29. function move_sinks_to_new_default {
  30. DEFAULT_SINK=$1
  31. pacmd list-sink-inputs | grep index: | grep -o '[0-9]\+' | while read SINK
  32. do
  33. pacmd move-sink-input $SINK $DEFAULT_SINK
  34. done
  35. }
  36.  
  37. set_default_playback_device_next
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement