It is teadious to go into sound settings, navigate through layers of setting pages and try to switch to a sound output port that you like.
In addition to the annoyance mentioned above, some laptops do not allow switching to internal speakers once a headphone is plugged into its internal headphone jack. The internal speaker will simply go mute.
This is the post to address these two inconveniences in our daily linux life.
This guide will be in following sections:
- pre-requisites on Manjaro (the one I am using)
- disable auto-mute function
- set audio source and sink using command line
- link to an entry in QuickLauncher in KDE Plasma
Disable auto-mute internal speaker
The amixer from
alsa-utils can be used to disable auto-mute.
A systemd unit file was created and enabled for user so that auto-mute will be disabled on every boot and does not require root privileges.
Create a systemd unit file at
[Unit] Description=Disable ALSA Auto-Mote Mode, able to switch between speaker and headphones [Service] Type=oneshot RemainAfterExit=true ExecStart=/usr/bin/amixer -c PCH sset 'Auto-Mute Mode' Disabled ExecStop=/usr/bin/amixer -c PCH sset 'Auto-Mute Mode' Enabled StandardOutput=journal [Install] WantedBy=default.target
Then start and enable it:
systemctl --user start disable-auto-mute systemctl --user enable disable-auto-mute
Set audio source and sink using command line
pacmd in package
pulseaudio let us control audio devices in command line.
First, explore your audio configuration by running:
The following truncated output is my audio configuration:
****** 1 card(s) available. index: 0 name: <alsa_card.pci-0000_00_1f.3> driver: <module-alsa-card.c> owner module: 6 properties: ****** profiles: ****** output:analog-stereo+input:analog-stereo: Analog Stereo Duplex (priority 6565, available: unknown) output:hdmi-stereo+input:analog-stereo: Digital Stereo (HDMI) Output + Analog Stereo Input (priority 5965, available: unknown) ****** active profile: <output:analog-stereo+input:analog-stereo> sinks: alsa_output.pci-0000_00_1f.3.analog-stereo/#0: Built-in Audio Analog Stereo sources: alsa_output.pci-0000_00_1f.3.analog-stereo.monitor/#0: Monitor of Built-in Audio Analog Stereo alsa_input.pci-0000_00_1f.3.analog-stereo/#1: Built-in Audio Analog Stereo ports: analog-input-internal-mic: Internal Microphone (priority 8900, latency offset 0 usec, available: unknown) properties: device.icon_name = "audio-input-microphone" ****** analog-output-speaker: Speakers (priority 10000, latency offset 0 usec, available: unknown) properties: device.icon_name = "audio-speakers" analog-output-headphones: Headphones (priority 9000, latency offset 0 usec, available: yes) properties: device.icon_name = "audio-headphones" hdmi-output-0: HDMI / DisplayPort (priority 5900, latency offset 0 usec, available: no) properties: device.icon_name = "video-display" ******
The available commands can be shown by running
We are going to use:
set-card-profile: switch between HDMI profile and internal analog-stereo profile
set-sink-port: switch between internal speakers and headphones
Switch to HDMI audio output
#!/bin/bash pacmd set-card-profile 0 output:hdmi-stereo+input:analog-stereo
Switch to internal stereo speaker output
#!/bin/bash # set to XPS internal sound card pacmd set-card-profile 0 output:analog-stereo+input:analog-stereo # set to speaker output pacmd set-sink-port 0 analog-output-speaker
Switch to internal headphones output
#!/bin/bash # set to XPS internal sound card pacmd set-card-profile 0 output:analog-stereo+input:analog-stereo # set to headphones output pacmd set-sink-port 0 analog-output-headphones
Save the above scripts into individual executable files. e.g.
Link to an entry in QuickLauncher in KDE Plasma
- Add Widgets > QuickLauncher
- Locate executable scripts
- change icon if necessary
Click and profit.