This is documentation for myself in hope of helping others. I do not accept any responsibility. Follow the instruction at your own risk. I tested it with Ubuntu 18.04 and it worked. This was also a practice for myself to automate something in Linux.
My freebuds 3 had a very low volume on Ubuntu 18.04 until I saw this answer. So running the following command 4 times resolved the issue
dbus-send --print-reply --system --dest=org.bluez /org/bluez/hci0/dev_<mac_address_of_headphones> org.bluez.MediaControl1.VolumeUp
Just note that the mac address should be seperated with _
underscore rather than :
which you may find in the bluetooth settings.
Still the problem is whenever I reconnect the headphones, I have to do this again. So I created a bash function for it.
The idea is to make Linux run the above command whenever it connects to my very specific Freebuds 3 automatically.
First we need to find information of the bluetooth device. Make sure the bluetooth headphone is not connected. Then run the following command
dmesg --follow
then connect the bluetooth headphone. A new line should be added to dmesg
output. For me the new line was like
[ 4036.621181] input: 04:8C:9A:F9:85:9A as /devices/virtual/input/input57
Now to find out more about this device we run
udevadm info -ap /devices/virtual/input/input57
Of course replace the paths with yours. The above command should output like this:
Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.
looking at device '/devices/virtual/input/input57':
KERNEL=="input57"
SUBSYSTEM=="input"
DRIVER==""
ATTR{name}=="04:8C:9A:F9:85:9A"
ATTR{phys}==""
ATTR{properties}=="0"
ATTR{uniq}==""
Now we have all the properties of the device. We need ATTR{name}=="04:8C:9A:F9:85:9A"
and SUBSYSTEM=="input"
.
Now we need to write a rule for kernel to execute the volume increase command whenever this bluetooth device is connected. Create a rule file like this:
sudo gedit /etc/udev/rules.d/50-my_bluetooth_rule.rules
add the following content to it and save it, of course replace the attributes value of your device from the udevadm
command for yourself:
ACTION=="add", SUBSYSTEM=="input", ATTR{name}=="04:8C:9A:F9:85:9A", RUN+="/home/your_username/bluetooth_rule.sh"
Now we need to create /home/your_username/bluetooth_rule.sh
file to be executed whenever the bluetooth device is added.
gedit /home/your_username/bluetooth_rule.sh
And add the following content to it with your MAC addresss replaced, my MAC was 04_8C_9A_F9_85_9A
:
Warning: When you run the following script manually, the volume of headphones increases suddenly. So be careful to not run it while you are listening to something. Too high volume may hurt your ears.
#!/bin/bash
for i in {0..3..1}; do dbus-send --print-reply --system --dest=org.bluez /org/bluez/hci0/dev_04_8C_9A_F9_85_9A org.bluez.MediaControl1.VolumeUp; done
The above runs the volume increase command 4 times. That is working for me. Tune it as you wish.
Now we need to reload the rules by running the following command
sudo udevadm control --reload
And that's it. Now whenever you connect the Freebuds 3 it should be at its highest internal volume level.
I got the above information from these links:
- https://askubuntu.com/a/60132
- https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux
- https://unix.stackexchange.com/a/543443
- https://unix.stackexchange.com/a/575093
I just followed the instruction in this link and everything worked for all of my bluetooth headsets:
THANK YOU!
Worked great to fix some super low-volume issues on a jabra elite 75t