Skip to content

Instantly share code, notes, and snippets.

@palcodes
Created September 25, 2025 08:24
Show Gist options
  • Select an option

  • Save palcodes/4e79bfd778611b700bc61ff0e9b2ba6b to your computer and use it in GitHub Desktop.

Select an option

Save palcodes/4e79bfd778611b700bc61ff0e9b2ba6b to your computer and use it in GitHub Desktop.
#!/bin/bash
# File: xm4.sh
# Force Sony XM4 to A2DP mode
HEADSET_MAC="DEVICE_ID"
# Get pipewire card number
CARD=$(pactl list cards | grep "$HEADSET_MAC" | awk '{print $1}')
if [ -z "$CARD" ]; then
echo "Headset not found. Ensure it is connected and paired."
exit 1
fi
echo "Reconnecting headset..."
# bluetoothctl flow
bluetoothctl <<EOF
disconnect $HEADSET_MAC
connect $HEADSET_MAC
exit
EOF
sleep 2
echo "Headset reconnected."
echo "Setting up A2DP"
pactl set-card-profile "$CARD" a2dp_sink
#Verify
pactl list cards short | grep "$HEADSET_MAC"
echo "Done. Your XM4 is now in A2DP mode."
echo $CARD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment