Skip to content

Instantly share code, notes, and snippets.

@sanskar10100
Created October 9, 2023 19:49
Show Gist options
  • Save sanskar10100/fa2eb78bcf431cec28dde509dd797288 to your computer and use it in GitHub Desktop.
Save sanskar10100/fa2eb78bcf431cec28dde509dd797288 to your computer and use it in GitHub Desktop.
Switch between audio profiles on Bluetooth Headset - Linux
#!/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
@sanskar10100
Copy link
Author

This assumes you're using BlueZ and pulseaudio (or pipewire-pulse)

@sanskar10100
Copy link
Author

If your headset doesn't have the same profiles, then you'll need to modify the script by using information from pactl list cards.

@sanskar10100
Copy link
Author

sanskar10100 commented Oct 9, 2023

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