Skip to content

Commit 8167f1c

Browse files
DonienDonien
authored andcommitted
Add script for toggling between available audio sinks (outputs)
1 parent 7a9191f commit 8167f1c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

switch_audio_sink.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/bash
2+
3+
# REQUIRES COMMAND `pactl` (PULSEAUDIO RELATED)
4+
5+
6+
7+
# Get available sinks and active default sink + the amount of sinks
8+
sink_list=($(pactl list sinks short | awk '{print $2}'))
9+
sink_num=$(pactl list sinks short | wc -l)
10+
sink_current=$(pactl info | grep -e "Default Sink" | awk '{print $3}')
11+
12+
13+
# Get index of current default sink
14+
for i in "${!sink_list[@]}";
15+
do
16+
if [[ "${sink_list[$i]}" = "$sink_current" ]]
17+
then
18+
index="$i"
19+
fi
20+
done
21+
22+
23+
# Decrement sink_num by 1 (zero-indexed)
24+
((sink_num="$sink_num"-1))
25+
26+
# Increment index or set to 0 if index==sink_num ("overflow" back to 0)
27+
if [[ "$index" = "$sink_num" ]]
28+
then
29+
index=0
30+
else
31+
((index="$index"+1))
32+
fi
33+
34+
# Set default sink to the next available in array
35+
pactl set-default-sink "${sink_list[$index]}"

0 commit comments

Comments
 (0)