summaryrefslogtreecommitdiff
path: root/scripts/.local/bin/setsink
blob: 793cfbfe7eb9c08b19694a5dd3d87b41db46ee92 (plain)
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
#!/bin/zsh

export DISPLAY=:0.0

devname=$(cat -)
if [[ -z "$devname" ]]; then
	echo "No device passed"
	return
fi

device=$(pactl list sinks short | grep $devname)
devid=$(echo $device | awk '{print $1}')
curdevid=$(pactl list sinks short | grep RUNNING | awk '{print $1}') 

echo "Swapping to device $device"
echo "Device ID $devid"
echo "Device name $devname"
echo "Current device ID $curdevid"
notify-send "Swapping to $devname"

pacmd set-default-sink $devid
if [[ -n "$curdevid" ]]; then
	pacmd suspend-sink $curdevid 1
fi
pacmd suspend-sink $devid 0 

#move all audio streams to the new sink
pactl list short sink-inputs | while read stream; do
	streamId=$(echo $stream | awk '{print $1}')
	echo 'Moving stream' $stream 'with id' $streamId
	pacmd move-sink-input "$streamId" "$devid"
done