(scripts) renamed select-audio-sink.sh, added selection of currently
used sink
This commit is contained in:
56
scripts/audio-sink-switcher.sh
Executable file
56
scripts/audio-sink-switcher.sh
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
select_audio_sink() {
|
||||
sinks="$(pactl list sinks)"
|
||||
|
||||
IFS=$(echo -en "\n\b")
|
||||
devices=($(echo "${sinks}" | grep -ioP "(?<=name: ).*$"))
|
||||
ids=($(echo "${sinks}" | grep -ioP "(?<=object.serial = ).*$"))
|
||||
names=($(echo "${sinks}" | grep -ioP "(?<=device\.description = ).*$"))
|
||||
unset IFS
|
||||
|
||||
if [[ "${#ids[@]}" != "${#names[@]}" ]] || [[ "${#ids[@]}" != "${#devices[@]}" ]]; then
|
||||
echo "ERROR: #ids (${#ids[@]}) != #names (${#names[@]})"
|
||||
return 1
|
||||
fi
|
||||
|
||||
unset number
|
||||
for n in ${!devices[@]}; do
|
||||
if [[ "${devices[$n]}" == "$(pactl get-default-sink)" ]]; then
|
||||
number=$n
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [[ -z "${number}" ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ((${#ids[@]} > 16)); then
|
||||
lines=16
|
||||
else
|
||||
lines=${#ids[@]}
|
||||
fi
|
||||
|
||||
selection="$(printf "%s\n" "${names[@]//\"/}" | fuzzel --lines ${lines} --dmenu --select-index ${number})"
|
||||
|
||||
if [[ -z "${selection}" ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
unset number
|
||||
for n in ${!names[@]}; do
|
||||
if [[ "${names[$n]}" == *"${selection}"* ]]; then
|
||||
number=$n
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -z "${number}" ]]; then
|
||||
echo "something went wrong.."
|
||||
return 1
|
||||
fi
|
||||
|
||||
pactl set-default-sink ${ids[$number]//\"/}
|
||||
}
|
||||
|
||||
select_audio_sink
|
||||
Reference in New Issue
Block a user