From 764673c51d5717d3d73623986a7694195d726774 Mon Sep 17 00:00:00 2001 From: awy Date: Sat, 16 Aug 2025 17:24:56 +0300 Subject: dmenuaudioswitch script --- .local/bin/dmenuaudioswitch | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 .local/bin/dmenuaudioswitch (limited to '.local/bin/dmenuaudioswitch') diff --git a/.local/bin/dmenuaudioswitch b/.local/bin/dmenuaudioswitch new file mode 100755 index 0000000..e878f23 --- /dev/null +++ b/.local/bin/dmenuaudioswitch @@ -0,0 +1,39 @@ +#!/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=$(printf "input\noutput" | mew -l 2 -p "Output or input devices?") + +case "$choice" in + "input") + select_input + ;; + "output") + select_output + ;; + *) + exit 1 + ;; +esac -- cgit v1.2.3