Advertisement
xWAFFELx

pulse audio switcher

Sep 10th, 2022 (edited)
1,321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.22 KB | Software | 0 0
  1. #!/bin/sh
  2.  
  3. # Title: Pulse Audio Switcher
  4. # Author: Ryan Young
  5. # Description:
  6. #    Cycles through each connected audio device.
  7. #    If you are using easyeffects it will skip over
  8. #    that so it doesn't set easyeffects as your default device.
  9. #    Make this file executable and then attach it to a hotkey
  10. #    in your DE or put it in your path somewhere.
  11.  
  12. #get all devices
  13. delete_var="Name:"
  14. SINKS=$(pactl list sinks | grep -e "Name:")
  15. SINKS=($SINKS)
  16. SINKS=( ${SINKS[@]/$delete_var})
  17. SINK_WIDTH=${#SINKS[@]}
  18. #echo $SINK_WIDTH
  19.  
  20. #get current device
  21. curr_device="$(pactl get-default-sink)"
  22.  
  23. #iterate through devices
  24. for i in "${!SINKS[@]}"
  25. do
  26.    echo $i
  27.    #set device to next in device list
  28.    if [ "$curr_device" = "${SINKS[$i]}" ];
  29.    then
  30.       next=$(($i + 1))
  31.  
  32.       #handle array overflow
  33.       if [ $next -ge $SINK_WIDTH ];
  34.       then
  35.          next=0
  36.       fi
  37.  
  38.       #do not set easyeffects as default device
  39.       if [ ${SINKS[$next]} = "easyeffects_sink" ];
  40.       then
  41.          next=$(($i+2))
  42.  
  43.          #recheck array overflow
  44.          if [ $next -ge $SINK_WIDTH ];
  45.          then
  46.             next=0
  47.          fi
  48.       fi
  49.       pactl set-default-sink ${SINKS[$next]}
  50.       break
  51.    fi
  52. done
Tags: BASH pactl
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement