Well, reading the topics that DK Bose and vanadium suggested and having done some more research to learning about bash script and Linux PulseAudio sound server, I came up with one solution:
We need to save the following script in a file (preferably in
/usr/local/bin/, as explained here), mark it as executable (by run
chmod +x over it) and then assigned it to a keyboard shortcut (optionally as explained here).
sound_output=$(pacmd list-cards | grep "active")
if [[ $sound_output = *"analog-stereo"* ]]; then
pactl set-card-profile 0 output:"$sound_output"
echo -e "PulseAudio sound server output set to $sound_output"
#!/bin/bash ensures that the interpreter for this script is bash, enabling extended syntax such as [[ ]].
- As cited here, the syntax
$( ) is "command substitution". This runs a command and use it's output to compose the line action. This way we save the
pacmd list-cards | grep "active" in
- As explained here, the use of
* in the condition turn it into a substring check.
- As answered here,
pactl set-card-profile 0 output: [card-profile] is the command to switch the sound server output, as