One-click audio output selection
↔ ![]()
I have two audio outputs: speakers and headphones. Both are always connected, and I want to switch between them quickly. Here’s a simple and elegant solution using a generic monitor widget for a panel, without installing any additional components.
A button-indicator will appear on the panel that toggles devices when clicked and displays the currently selected device.
![]()
The image in the middle shows this button.
The solution isn’t directly related to the Qubes OS, just to Xfce.
Add a generic_monitor widget to a panel. For now, just add it.
In Dom0, create a file, for example:
/home/user/bin/audio_switch.pl
#!/usr/bin/perl
#
# !!! Replace the numbers 54, 55, 20
#
use v5.40;
my %audio_icon = (
54 => {
icon => 'audio-headphones',
next => 55,
},
55 => {
icon => 'audio-speakers',
next => 54,
},
);
my $genmon = 20;
my $audio = join '|', keys %audio_icon;
my($sink) = `wpctl status` =~ /\*\s*($audio)\./;
my $cmd = sprintf "sh -c 'wpctl set-default %d && xfce4-panel --plugin-event=genmon-%d:refresh:bool:true'",
$audio_icon{$sink}{next}, $genmon;
printf "<icon>%s</icon><iconclick>%s</iconclick><tool>%s</tool>",
$audio_icon{$sink}{icon},
$cmd,
$audio_icon{$sink}{icon},
;
Replace the numbers 54, 55, 20 with your own.
How do you find them?
54 and 55 are the identifiers for your audio devices. You can view them in the console by running wpctl status under the “Audio - Sinks:” section.
20 is the widget name of the particular genmon instance, like “genmon-20”. To get this name, go to the panel properties screen and on the Items tab, hover your mouse over the genmon plugin to get it’s internal name.
You’ll also need to come up with names for the cute icons using the system’s default labels, such as audio-headphones and audio-speakers. It’s a creative process ![]()
Run chmod +x /home/user/bin/audio_switch.pl
Open the generic_monitor’s properties and enter /home/user/bin/audio_switch.pl in the “Command” field.
Set the “Period (s)” to a fairly long value, such as 300.
Click Save and enjoy your new button-indicator. ![]()