From 638bf99508a0abc509f4e7d1eab94b11fe8ed9b4 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Tue, 3 Jan 2023 19:53:28 -0800 Subject: [PATCH] Added select-sound-output.sh --- select-sound-output.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 select-sound-output.sh diff --git a/select-sound-output.sh b/select-sound-output.sh new file mode 100755 index 0000000..f90d66c --- /dev/null +++ b/select-sound-output.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env zsh +local info="$(pactl list sinks)" +local default_name="$(pactl info | grep -Po '(?<=Default Sink: ).+')" +local ids=(${(@f)"$(echo "${info}" | grep -Po '(?<=Sink #).+')"}) +local names=(${(@f)"$(echo "${info}" | grep -Po '(?<=Name: ).+')"}) +local descs=(${(@f)"$(echo "${info}" | grep -Po '(?<=Description: ).+')"}) +local default_id="" +local query_string="" +for ((i = 1; i <= "${#ids}"; ++i)); do + if [[ "${names[${i}]}" == "${default_name}" ]]; then + default_id="${ids[${i}]}" + fi + query_string+="${ids[${i}]}: ${descs[${i}]} (${names[${i}]})\n" +done +local choice +choice="$(echo "${query_string%"\n"}" | dmenu -p "${default_id}")" +if (( "${?}" != 0 )); then + exit +fi +local selected_id="$(echo "${choice}" | grep -Eo '^[0-9]+')" +pactl set-default-sink "${selected_id}" +local selected_name=$(echo "${choice}" \ + | cut -c "$(("${#selected_id}" + 3))-" \ + | grep -Po '^.+(?= \()') +notify-send 'Output Device' "${selected_name} (${selected_id})"