File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /usr/bin/bash
2+ 
3+ #  REQUIRES COMMAND `pactl` (PULSEAUDIO RELATED)
4+ 
5+ 
6+ 
7+ #  Get available sources and active default source + the amount of sources
8+ #  Also exclude monitors
9+ source_list=($( pactl list sources short |  grep -v ' .monitor' |  awk ' {print $2}' ) 
10+ source_num=$( pactl list sources short |  grep -v ' .monitor' |  wc -l) 
11+ source_current=$( pactl info |  grep -e ' Default Source' |  awk ' {print $3}' ) 
12+ 
13+ 
14+ #  Get index of current default source
15+ for  i  in  " ${! source_list[@]} " ; 
16+ do 
17+     if  [[ " ${source_list[$i]} " =  " $source_current " 
18+     then 
19+         index=" $i " 
20+     fi 
21+ done 
22+ 
23+ 
24+ #  Decrement source_num by 1 (zero-indexed)
25+ (( source_num= "$source_num "- 1 )) 
26+ 
27+ #  Increment index or set to 0 if index==source_num ("overflow" back to 0)
28+ if  [[ " $index " =  " $source_num " 
29+ then 
30+     index=0
31+ else 
32+     (( index= "$index "+ 1 )) 
33+ fi 
34+ 
35+ #  Set default source to the next available in array
36+ pactl set-default-source " ${source_list[$index]} " 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments