-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetsound
executable file
·35 lines (28 loc) · 1.4 KB
/
setsound
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
# RHEL8 lenovo p50 laptop running with my poly headset
# once I power on the headset, pulse audio sets it as the default audio device
#
# then after a reboot, if the poly headset is off, pulse audio still has it set as default, no sound
# run this script after logging in to reset to the internal speakers
# parse through output from pacmd list-sinks looking for a $target device name and set it as the default sink
# index: 1
# name: <alsa_output.usb-Plantronics_Poly_BT600_2b75408a6ed54605a234ea452553ecc0-00.analog-stereo>
# in control panel audio set the default device, then run the following to see which is set.
# pacmd list-sinks | grep -e 'name:' -e 'index:'
# mine looked like :
# name: <alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi___ucm0005.hw_sofhdadsp__sink>
# but the ucm005 number part can vary, so come up with a regex to match
target="HiFi___.*.hw_sofhdadsp__sink"
IFS=$'\n'; # need ifs so pacmd output does not break on spaces
count=1
# then we loop through the pulseaudio sinks looking for a matching name. when its found, set the default to $count
for i in $(pacmd list-sinks | grep -e 'name:'); do
echo $i | egrep $target > /dev/null
if [ "$?" == "0" ]; then
echo "Found internal speaker at index $count == $i "
echo "setting default sound device to $count"
pacmd set-default-sink $count
else
count=$((count+1))
fi
done