Skip to content

Instantly share code, notes, and snippets.

@rkok
Last active April 16, 2024 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkok/58ee4d27dd31cddb81385c78cd3cc2fa to your computer and use it in GitHub Desktop.
Save rkok/58ee4d27dd31cddb81385c78cd3cc2fa to your computer and use it in GitHub Desktop.
PulseAudio headset mode toggler
#!/usr/bin/env bash
#######################
# btheadset_toggle.sh
#
# Toggles bluetooth headset mode between
# A2DP (high quality, no microphone)
# and headset (low quality + microphone).
#
# Usage: ./btheadset_toggle.sh
#
# Setup:
# 1. Run `pacmd list-cards`
# 2. Check what the name of your card is and fill it in below
# 3. Check the naming of PROFILE_A2DP / PROFILE_HSP
# and modify below if necessary
# 4. Recommended: create a panel launcher to run this script
#######################
ID="bluez_card.AA_BB_CC_DD_EE_FF" # <-- Your card ID here
PROFILE_A2DP='a2dp_sink'
#PROFILE_HSP='headset_head_unit'
PROFILE_HSP='handsfree_head_unit'
CUR_PROFILE="$(pacmd list-cards | grep -A 40 $ID | grep 'active profile' | head -1 | awk '{print $3}' | sed 's/[<>]//g')"
if [ "$CUR_PROFILE" == "$PROFILE_A2DP" ]; then
# Need to do this twice for some reason
pacmd set-card-profile $ID $PROFILE_HSP
pacmd set-card-profile $ID $PROFILE_HSP
else
pacmd set-card-profile $ID $PROFILE_A2DP
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment