-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaudio-switcher.sh
executable file
·46 lines (36 loc) · 1.31 KB
/
audio-switcher.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
if [[ "$SNAP_ARCH" == "amd64" ]]; then
ARCH="x86_64-linux-gnu"
elif [[ "$SNAP_ARCH" == "armhf" ]]; then
ARCH="arm-linux-gnueabihf"
elif [[ "$SNAP_ARCH" == "arm64" ]]; then
ARCH="aarch64-linux-gnu"
else
ARCH="$SNAP_ARCH-linux-gnu"
fi
# Pulseaudio export
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SNAP/usr/lib/$ARCH/pulseaudio
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SNAP/lib/$ARCH
SINKS_COUNT=`pactl list sinks short | awk '{print $1}' | wc -l`
SINKS=(`pactl list sinks short | awk '{print $1}'`)
RUNNING_SINK=(`pactl list sinks short | grep RUNNING | awk '{print $1}'`)
INPUTS=(`pactl list sink-inputs short | awk '{print $1}'`)
for i in ${!SINKS[*]}; do
if [[ ${SINKS[$i]} == $RUNNING_SINK ]]; then
SINK_INDEX=$i
fi
done
if [[ ${#SINKS[@]} -ne 0 ]] && [[ ${SINKS[-1]} -eq $RUNNING_SINK ]]; then
pactl set-default-sink ${SINKS[0]}
for i in ${INPUTS[*]}; do
pactl move-sink-input $i ${SINKS[0]}
done
notify-send "Switching to `pactl list sinks short | grep RUNNING | awk '{print $2}' | awk -F "." '{print $NF}'`"
else
NEW_INDEX=$((SINK_INDEX+1))
pactl set-default-sink ${SINKS[$NEW_INDEX]}
for i in ${INPUTS[*]}; do
pactl move-sink-input $i ${SINKS[$NEW_INDEX]}
done
notify-send "Switching to `pactl list sinks short | grep RUNNING | awk '{print $2}' | awk -F "." '{print $NF}'`"
fi