aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/dmenuaudioswitch
blob: 8c2b3676b60fba808cdfe0cc3f2e050dc294a2be (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
36
37
38
39
40
#!/bin/sh

select_output()
{
  listofdevices=$(wpctl status | awk '/Sinks:/{flag=1; next} /^ ├─/{flag=0} flag {
    line=$0
    gsub(/^ *[│├─]* */,"",line)   # nuke leading garbage
    print line
  }' | sed 's/ \[vol: [^]]*\]//g' | rg -v '^$' | sed 's/[[:space:]]\+$//')
  device=$( printf "%s" "$listofdevices" | mew -l 10 | awk '{match($0,/[0-9]+/); print substr($0,RSTART,RLENGTH)}')
  wpctl set-default $device && notify-send "$(printf "%s" "$listofdevices" | rg $device) is now default output device" && exit 0
  notify-send "Something went wrong"
}

select_input()
{
  listofdevices=$(wpctl status | awk '/Sources:/{flag=1; next} /^ ├─/{flag=0} flag {
    line=$0
    gsub(/^ *[│├─]* */,"",line)   # nuke leading garbage
    print line
  }' | sed 's/ \[vol: [^]]*\]//g' | rg -v '^$' | sed 's/[[:space:]]\+$//')
  device=$( printf "%s" "$listofdevices" | mew -l 10 | awk '{match($0,/[0-9]+/); print substr($0,RSTART,RLENGTH)}')
  wpctl set-default $device && notify-send "$(printf "%s" "$listofdevices" | rg $device) is now default input device" && exit 0
  notify-send "Something went wrong"
}

choice=$1
# choice=$(printf "input\noutput" | mew -l 2 -p "Output or input devices?")

case "$choice" in
  "input")
    select_input
    ;;
  "output")
    select_output
    ;;
  *)
    exit 1
    ;;
esac