Skip to content

Instantly share code, notes, and snippets.

@ngandrass
Created July 13, 2023 10:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngandrass/dfdd1f2ea833eea5c178ab56193e9dbe to your computer and use it in GitHub Desktop.
Save ngandrass/dfdd1f2ea833eea5c178ab56193e9dbe to your computer and use it in GitHub Desktop.
Switch current default audio sink to the next available sink using pactl
#!/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