#!/bin/sh
#
# switch between the HFP and A2DP Bluetooth profiles for the beats fit pro.
#
# the headphones are going to be used as simple high quality headphones most of the time,
# but this script will make it easy to switch to HFP and back to A2DP when needed.

pacard="$(pactl -f json list cards | jq -r '.[] | select(.name == "bluez_card.F8_66_5A_31_BC_46")')"

if [ -z "${pacard}" ]; then
  notify-send "beats toggle" "beats not found in PulseAudio!"
  exit 1
fi

activeProfile="$(echo "${pacard}" | jq -r '.active_profile')"

if [ "${activeProfile}" = "a2dp-sink-sbc_xq" ]; then
  pactl set-card-profile bluez_card.F8_66_5A_31_BC_46 headset-head-unit-msbc
  notify-send "beats toggle" "Switched to the HFP profile."
elif [ "${activeProfile}" = "headset-head-unit-msbc" ]; then
  pactl set-card-profile bluez_card.F8_66_5A_31_BC_46 a2dp-sink-sbc_xq
  notify-send "beats toggle" "Switched to the A2DP profile."
else
  notify-send "beats toggle" "Unknown profile: ${activeProfile}"
  exit 1
fi
