Added select-sound-output.sh

This commit is contained in:
Alexander Rosenberg 2023-01-03 19:53:28 -08:00
parent 8ddd293b10
commit 638bf99508
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

25
select-sound-output.sh Executable file
View File

@ -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})"