Created
October 9, 2023 19:49
-
-
Save sanskar10100/fa2eb78bcf431cec28dde509dd797288 to your computer and use it in GitHub Desktop.
Switch between audio profiles on Bluetooth Headset - Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Get the name of the Bluetooth headset | |
device_name=$(pactl list cards | grep -B 20 "device.form_factor = \"headset\"" | grep "Name" | awk '{print $2}') | |
# Get the current active profile for the headset | |
active_profile=$(pactl list cards | grep -A 40 "Name: $device_name" | grep "Active Profile" | cut -d ' ' -f3) | |
# Toggle between the two profiles | |
# Complete list of available profiles can be seen by using pactl list cards | |
if [ "$active_profile" == "a2dp-sink" ]; then | |
pactl set-card-profile "$device_name" headset-head-unit-msbc | |
echo "Switched to HSP" | |
else | |
pactl set-card-profile "$device_name" a2dp-sink | |
echo "Switched to A2DP" | |
fi |
If your headset doesn't have the same profiles, then you'll need to modify the script by using information from pactl list cards
.
For easy access, create a desktop entry and put it in your panel (or assign a shortcut)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This assumes you're using
BlueZ
andpulseaudio
(orpipewire-pulse
)