Last active
August 24, 2021 19:24
-
-
Save aalhitennf/bf1d713c830c8a4ee0f3c08516894ff0 to your computer and use it in GitHub Desktop.
pactl loop outputs with ignore filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CURRENT_SINK=$(pactl info | grep 'Default Sink' | awk -F ':' '{print $2}') | |
readarray -t SINKS < <(pactl list sinks | grep 'Name: ' | awk -F ':' '{print $2}') | |
IGNORE_SINKS=() | |
VALID_SINKS=() | |
for i in "${!SINKS[@]}" | |
do | |
sink=${SINKS[$i]} | |
filter=false | |
for s in "${!IGNORE_SINKS[@]}" | |
do | |
pattern=${IGNORE_SINKS[$s]} | |
if [[ "$sink" == *"$pattern"* ]] || [[ "$sink" == *"$CURRENT_SINK"* ]]; then | |
filter=true | |
fi | |
done | |
if [ $filter = false ]; then | |
VALID_SINKS[${#VALID_SINKS[@]}]=$sink | |
fi | |
done | |
for i in "${!VALID_SINKS[@]}" | |
do | |
sink=${VALID_SINKS[$i]} | |
ni=$1 | |
(( ni++ )) | |
if [ $ni = ${#VALID_SINKS[@]} ]; then | |
ni=0 | |
fi | |
next=${VALID_SINKS[$ni]} | |
echo $next | |
pactl set-default-sink $next | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IGNORE_SINKS syntax for array is i.e.
IGNORE_SINKS=("hdmi" "G533")