I am using Fossapup64 F96 on a Dell Latitude. All is working perfectly including sound with pulseaudio.
In the pulseaudio volume control window it lists 3 output options:
Speakers
Headphones
Line Out
Context:
I often use an external audio conference speaker which plugs into the Headphone jack.
If I boot the machine without this speaker connected, the system rightly assigns the audio output to "Speakers" and sound works fine.
If I then plug the speaker into the headphone jack, the system rightly updates, and assigns the audio output to "Headphones" and sound works fine.
However - if I reboot the machine leaving the speaker plugged in, the system assigns the audio ouput to "Speakers" and before the sound can be heard I have to either:
manually open pulseadio volume control and select "Headphones" -or
manually unplug the speaker, and then replug it.
I would like to create a small script which will test for the presence of the Headphones and set the audio output accordingly.
What file can I interrogate to find this information?
I'm thinking my script would look something like this:
Code: Select all
audiodevice=<test some condition>
if [ $audiodevice == "Headphones" ]; then
pactl set-sink-port 0 analog-output-headphones
else
pactl set-sink-port 0 analog-output-speaker
fi
Can anyone help please?
Never mind - managed to work it out for myself. This works for me:
Code: Select all
headphones=`amixer contents | grep -A 2 numid=4 | grep values=on | tail -c 3`
echo "headphones=$headphones"
if [ $headphones == "on" ]; then
echo "headphone is connected"
pactl set-sink-port 0 analog-output-headphones
else
echo "headphone not connected"
pactl set-sink-port 0 analog-output-speaker
fi
# turn on volume button
pactl set-sink-mute @DEFAULT_SINK@ 0
# set volume to 50%
pactl set-sink-volume @DEFAULT_SINK@ 50%