-
Star
(115)
You must be signed in to star a gist -
Fork
(11)
You must be signed in to fork a gist
-
-
Save egelev/2e6b57d5a8ba62cf6df6fff2878c3fd4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash | |
function get_headphones_index() { | |
echo $(pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}') | |
} | |
function get_headphones_mac_address() { | |
local temp=$(pacmd list-cards | grep bluez_card -C20 | grep 'device.string' | cut -d' ' -f 3) | |
temp="${temp%\"}" | |
temp="${temp#\"}" | |
echo "${temp}" | |
} | |
function _control_bluethoot_headphones() { | |
local op=${1} | |
local hp_mac=${2} | |
echo -e "${op} ${hp_mac}\n quit" | bluetoothctl | |
} | |
function disconnect_bluetooth_headphones() { | |
local hp_mac=${1} | |
_control_bluethoot_headphones "disconnect" ${hp_mac} | |
} | |
function connect_bluetooth_headphones() { | |
local hp_mac=${1} | |
_control_bluethoot_headphones "connect" ${hp_mac} | |
} | |
function _set_headphones_profile() { | |
local profile=${1} | |
pacmd set-card-profile $(get_headphones_index) ${profile} | |
} | |
function set_headphones_profile_a2dp_sink() { | |
_set_headphones_profile "a2dp_sink" | |
echo "Bluethoot headphones a2dp_sink" | |
} | |
function set_headphones_profile_off() { | |
_set_headphones_profile "off" | |
echo "Bluethoot headphones profile off" | |
} | |
function main() { | |
local hp_mac=$(get_headphones_mac_address) | |
set_headphones_profile_off | |
sleep 2s | |
disconnect_bluetooth_headphones ${hp_mac} | |
sleep 6s | |
connect_bluetooth_headphones ${hp_mac} | |
sleep 3s | |
set_headphones_profile_a2dp_sink | |
} | |
main |
No matter what I do (the order of turning headphone pairing on and turning bluetooth on, or leaving bluetooth off, etc.), I get the following messages in Ubuntu 20.04 when I run the script:
You need to specify a profile by its name. Bluethoot headphones profile off Agent registered [bluetooth]# disconnect Missing device address argument [bluetooth]# quit Agent registered [bluetooth]# connect Missing dev argument [bluetooth]# quit You need to specify a profile by its name. Bluethoot headphones a2dp_sink
The headphones are Sony MDR-ZX780DC and they work just fine on iphone. (I did turn iphone bluetooth off)
Does anyone have any suggestion?
Hello @leka0024.
Can you please provide the output of the following command: pacmd list-cards | grep bluez_card -B1 -A50
?
If it is OK, it would be helpful to execute it twice:
- when the headphones are not connected
- when you connect them through the Ubuntu UI (don't pay attention to the profile - HSP/HFP or A2DP)
Thank you.
Hello @leka0024.
Can you please provide the output of the following command:pacmd list-cards | grep bluez_card -B1 -A50
?
If it is OK, it would be helpful to execute it twice:* when the headphones are not connected * when you connect them through the Ubuntu UI (don't pay attention to the profile - HSP/HFP or A2DP)
Thank you.
Hi @egelev ,
Nothing returns with the pipe'd command you suggest. If I just run pacmd list-cards
I get this info:
1 card(s) available.
index: 0
name: <alsa_card.pci-0000_00_1f.3-platform-skl_hda_dsp_generic>
driver: <module-alsa-card.c>
owner module: 23
properties:
alsa.card = "0"
alsa.card_name = "sof-hda-dsp"
alsa.long_card_name = "LENOVO-82HS-IdeaPadFlex514ITL05-LNVNB161216"
alsa.driver_name = "snd_soc_skl_hda_dsp"
device.bus_path = "pci-0000:00:1f.3-platform-skl_hda_dsp_generic"
sysfs.path = "/devices/pci0000:00/0000:00:1f.3/skl_hda_dsp_generic/sound/card0"
device.bus = "pci"
device.vendor.id = "8086"
device.vendor.name = "Intel Corporation"
device.product.id = "a0c8"
device.string = "0"
device.description = "sof-hda-dsp"
module-udev-detect.discovered = "1"
device.icon_name = "audio-card-pci"
Is that helpful?
When I have turned Bluetooth on in the Ubuntu settings, it can never see my headphones (turned on, in pairing mode, and iphone bluetooth off), so I don't believe it has ever "connected".
Thanks for any suggestions!
Hi, @leka0024. Thank you for the info. Unfortunately, it looks like this is another issue. This script only changes the profile from HSP/HFP to A2DP once the headphones are successfully connected. I am sorry, it looks like some sort of incompatibility issue.
Does someone has the problem that the Headset Mode is working but on A2DP no sound can be heard? It was workings since i upgraded to 20.xx but since one week or so i have problems again. Removing and Repairing does sometimes fix the issue.
WH-1000XM3, newest firmware.
i am unable to as well on Linux Mint 20.1
Does someone has the problem that the Headset Mode is working but on A2DP no sound can be heard? It was workings since i upgraded to 20.xx but since one week or so i have problems again. Removing and Repairing does sometimes fix the issue.
WH-1000XM3, newest firmware.
This may or may not resolve your issue. I've found that on first connect it will not work with the headphones. I've had the Sony WH-1000xm3 and xm4's. My current simple fix is to connect the headphones, disconnect them and reconnect. Then click on the speaker icon and choose the applications tab and select the sound output to be the headphones. This is not a great work around, but it's the best that I've been able to come up with.
I've tested this on Ubuntu, mint and Mx Linux.
Does this work with Pipewire ?
thank you so much !
worked for me on Linux Mint 20.2 Cinnamon and Sony WH-1000XM3 headset .
happy new year !
Hi Emil. I happened to find your script just today ... and I love it!, very useful. Thank you! ( :
Hi Emil. I happened to find your script just today ... and I love it!, very useful. Thank you! ( :
I'm glad it is still useful :).
Thank you very much for this - worked perfectly out of the box with my Bose QCII Headset on Ubuntu 22.04.
Thanks, worked for me!
Thank you @egelev for the script. I changed it to make it wotk with PipeWire. You can see it here: https://gist.github.com/tbulligan/b92e85a6e89e218d711a97cfa38f855e
No matter what I do (the order of turning headphone pairing on and turning bluetooth on, or leaving bluetooth off, etc.), I get the following messages in Ubuntu 20.04 when I run the script:
The headphones are Sony MDR-ZX780DC and they work just fine on iphone. (I did turn iphone bluetooth off)
Does anyone have any suggestion?