Created
July 13, 2023 10:37
-
-
Save ngandrass/dfdd1f2ea833eea5c178ab56193e9dbe to your computer and use it in GitHub Desktop.
Switch current default audio sink to the next available sink using pactl
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
#!/usr/bin/env bash | |
# | |
# Switches the current default audio sink to the next available sink using pactl. | |
# Get all sinks via pactl | |
sinks=$(pactl list short sinks | cut -f 2) | |
# Get current default sink | |
current_sink=$(pactl info | grep "Default Sink" | cut -d ' ' -f 3) | |
# Get sink after current sink | |
next_sink=$(echo "$sinks" | grep -A1 "$current_sink" | tail -n1) | |
if [ "$next_sink" == "$current_sink" ]; then | |
next_sink=$(echo "$sinks" | head -n1) | |
fi | |
# Set next sink as default | |
pactl set-default-sink "$next_sink" | |
echo "Switched from $current_sink to $next_sink" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment