Skip to content

Instantly share code, notes, and snippets.

@aalhitennf
Last active August 24, 2021 19:24
Show Gist options
  • Save aalhitennf/bf1d713c830c8a4ee0f3c08516894ff0 to your computer and use it in GitHub Desktop.
Save aalhitennf/bf1d713c830c8a4ee0f3c08516894ff0 to your computer and use it in GitHub Desktop.
pactl loop outputs with ignore filter
#!/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
@aalhitennf
Copy link
Author

aalhitennf commented Aug 24, 2021

IGNORE_SINKS syntax for array is i.e. IGNORE_SINKS=("hdmi" "G533")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment