summaryrefslogtreecommitdiff
path: root/scripts/.local/bin/chsink
blob: 9948ff6908faf985cba749e21b52da25714664c8 (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
#!/bin/sh

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

    tgtdev=$(pactl list sinks short | grep "$tgtdevname")
    tgtdevid=$(echo "$tgtdev" | awk '{print $1}')
    curdevid=$(pactl list sinks short | grep RUNNING | awk '{print $1}')

    echo "Swapping to device $tgtdev"
    echo "Device ID $tgtdevid"
    echo "Device name $tgtdevname"
    echo "Current device ID $curdevid"
    notify-send "Swapping to $tgtdevname"

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

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

pactl list sinks short | awk '{print $2}' | cdmenu -l 32 | setsink