26 lines
982 B
Bash
Executable File
26 lines
982 B
Bash
Executable File
#!/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})"
|