How can I get sound on headphones without switching back to 'Speakers' manually?

Solution 1:

Pulseaudio always tries to switch to a newly available audio port when it becomes available. To stop this we can edit our default.pa. This file is located in /etc/pulse (defining settings for all users) or in ~/.pulse (to override these settings for a single user). Just comment out this line to stop pulseaudio from switching ports as follows:

# load-module module-switch-on-port-available

To take effect we need to restart pulseaudio server with pulseaudio -k (or restarting our session).

Whenever you edit the /etc/pulse/default.pa please make a backup first to be able to restore previous settings in case something goes wrong.