A minimalist Bash script that switches the system default PulseAudio sink to the next available sink.
This script was created for use as the click handler of Waybar's PulseAudio module. With the following module configuration, each click switches to the next sink:
{
"pulseaudio": {
...
"on-click": "pulseaudio-switch-sink"
}
}The script must be available in Waybar's PATH, or you use the full path instead.
pactlwith JSON output supportjq
Run the script without arguments:
pulseaudio-switch-sinkEach invocation sorts the sinks listed by pactl by numeric index and selects the next sink after the current default. The selection wraps from the highest-indexed sink to the lowest-indexed sink.
If the current default cannot be identified, the script selects the lowest-indexed sink. If no sinks are available or the selected sink is already the default, the script makes no change.
Successful switches and no-ops produce no output and exit with status 0. Errors are written to standard error and exit with status 1.
The script changes the system default sink but does not move audio streams that are already playing.