Skip to content

Instantly share code, notes, and snippets.

@dalibor-drgon
Created August 4, 2021 16:13
Show Gist options
  • Select an option

  • Save dalibor-drgon/27ecb8e4bb9d8e971d425896b8e22a49 to your computer and use it in GitHub Desktop.

Select an option

Save dalibor-drgon/27ecb8e4bb9d8e971d425896b8e22a49 to your computer and use it in GitHub Desktop.
A2DP vs HSP toggle for PulseAudio PipeWire Linux Fix
#! /bin/bash
# Script that finds connected bluetooth device (must be exactly 1 device!)
# and switches between a2dp and hsp (the second option also set default source
# to the newly created hsp microphone.)
STATE_FILE=~/bt.txt # where to store the state (2 bytes)
DEVICE=$(pactl list cards | grep "Name: bluez" | sed "s/[ \t]*Name: //")
CUR=$(cat $STATE_FILE)
echo "Card: $DEVICE"
if [ $CUR = "1" ]; then
echo "a2dp"
pactl set-card-profile $DEVICE a2dp-sink
echo "0" > $STATE_FILE
else
echo "headset"
pactl set-card-profile $DEVICE headset-head-unit
pactl set-default-source $(echo $DEVICE | sed 's/_card\./_input./g').headset-head-unit
echo "1" > $STATE_FILE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment