EDIT: I've corrected the script and added a small explanation on how to find out your sound card id.
In the last few days I've been busy installing and configuring the new Fedora 25 on my computers. I've installed it on my desktop and on my MacBook as well, and so far everything as been running quite smoothly! Nevertheless, nothing is ever 100% perfect, and I've run into a few quirks here and there. One of those quirks is that I couldn't find a way to change the audio output between my headphones and my speakers, having them connected at the same time!
The symptoms were:
- If I plugged the headphones in, sound started to play and the speakers were muted, as intended.
- If I unplugged the headphones, sound started to play on the speakers. So far so good.
pacmd list-sinks | grep analog-outputand check your sinks port names.
Now I know that I want to change between
analog-output-headphones. Check your output to find out which naming scheme you're using.
- Now run
pacmd list-cards | grep alsa_output:
My device will be
alsa_output.pci-0000_00_1b.0.analog-stereo, since I'm not using HDMI sound. You have to look at yours and see if you find something similar. It should be easy to identify.
vim audio-switcher(or any other name you like).
- Copy the following script and replace
SECONDDEVICEwith the values from the previous steps.
IDwith your own sound card id. You can find it using
cat /proc/asound/cardsand looking at the leftmost number.
- Mark the script as executable:
chmod +x audio-switcher.
- You're done! Just run it with
./audio-switcherand watch as your sound jumps from the speakers to the headphones and the other way around each time you run it. You can move the script to
mv audio-switcher /usr/local/bin) or symlink it (
sudo ln -s /path/to/audio-switcher /usr/local/bin/) so you can call it from anywhere with
audio-switcher. You can also assign a keyboard shortcut by going to
+and setting a name of your choice, the
audio-switchercommand and a shortcut you like.