I temporary solved this issue by applying following workaround (dirty solution).
Created systemd user service:
Code:
> cat $HOME/.config/systemd/user/front-headphones-switch-handler.service
[Unit]
Description=Run front-headphones-switch-handler
[Service]
; Type=oneshot
Type=simple
ExecStart=/usr/local/bin/front-headphones-switch-handler
Restart=on-failure
RestartSec=5
[Install]
WantedBy=default.target
And bash script:
Code:
> cat /usr/local/bin/front-headphones-switch-handler
#!/bin/bash
TARGET_DEVICE="Headphones"
while true; do
SINK_SELECTED_STATUS=`cat $HOME/.front-headphones-sink-selected-status`
if [ `pactl list sinks short | grep $TARGET_DEVICE | wc -l` -lt 1 ]; then
pacmd load-module module-alsa-sink sink_name=$TARGET_DEVICE sink_properties=device.description=$TARGET_DEVICE device=hw:Audio,1 control='PCM',1
pactl set-default-sink alsa_output.usb-Generic_USB_Audio-00.analog-stereo 2>/dev/null
fi
are_front_headphones_attached=$(pacmd list-sinks | grep 'analog-output-headphones' | grep active | wc -l)
if [ $are_front_headphones_attached -gt 0 ]; then
if [ "$SINK_SELECTED_STATUS" == "FALSE" ]; then
pactl set-default-sink "$TARGET_DEVICE" 2>/dev/null
if [ $? -eq 0 ]; then
echo TRUE > $HOME/.front-headphones-sink-selected-status
else
notify-send "front-headphones-switch-handler" "ERROR in setting front-headphones as output device"
fi
fi
else
is_speaker_already_default=$(pacmd list-sinks | grep 'analog-output-speaker' | grep active | wc -l)
if [ $is_speaker_already_default -gt 0 ]; then
if [ "$SINK_SELECTED_STATUS" == "FALSE" ]; then
sleep 0.5
continue
fi
fi
pactl set-default-sink alsa_output.usb-Generic_USB_Audio-00.analog-stereo 2>/dev/null
if [ $? -eq 0 ]; then
echo FALSE > $HOME/.front-headphones-sink-selected-status
else
notify-send "front-headphones-switch-handler" "ERROR in setting speaker as output device"
fi
fi
sleep 0.5
done
exit 0
So that each time I attach my headphones to the front AUX jack, the bash daemon detect them and it switches to new dedicated sink for redirecting the audio.
Bookmarks