3

When I unplug the headphones, the sound device is set automatically to "Digital Output (S/PDIF)" instead of the "HDMI / Displayport" that I was using before plugging the headphones.

How can I configure the system so that it uses the headphones when they are connected, and the HDMI output when they are not? I do not want the system to use "Digital Output (S/PDIF)" at all.

Óscar
  • 1,006

1 Answers1

2

According to 'user.dz' - you can trigger a script when headphones is disconnected.

when Headphone disconnects - use ACPI to trigger a script

(What code is executed when headphones are disconnected?).

In most systems if not all, ACPI can handle this event. To test that:

Run acpi_listen

Unplug & replug headphones, example output: (mic/ears share in same >jack on my laptop)

jack/headphone HEADPHONE unplug jack/microphone MICROPHONE unplug jack/headphone HEADPHONE plug jack/microphone MICROPHONE plug

Put your-script.sh in /etc/acpi/

Add an event trigger file for your script in /etc/acpi/events/

event=jack/headphone HEADPHONE unplug action=/etc/acpi/your-script.sh

Check the other files there to learn from.

You may need to restart acpid service to reload changed rules in >/etc/acpi /events/

sudo service acpid restart

Default Headphone setting within terminal for the script

Could be done with recommendation to 'Takkat's answer from

(How can I change the default audio device from command line?)

You can control PulseAudio thoroughly through the command line using pacmd and >pactl commands. For options see man pages or the wiki at PulseAudio:

pacmd list-sinks (or pactl list short sinks) for name or index number of possible >sinks

pacmd set-default-sink "SINKNAME" to set the default output sink

pacmd set-default-source "SOURCENAME" to set the default input

pacmd set-sink-volume index volume

pacmd set-source-volume index volume for volume control (65536 = 100 %, 0 = mute; or a bit more intuitive 0x10000 = 100 %, 0x7500 = 75 %, 0x0 = 0 %)

and many many more CLI options.

This is my first answer - I hope it helps and pardon/let me know if theres anything I should've done differently.