#!/bin/sh # # Toggle between the Headset (HSP/HFP) and High Fidelity profiles using PipeWire # # Usage: ./toggle_pw_headset {cycle|a2dp|headset} ################################################################################ DEVICES="$(pw-dump | jq 'map(select(.info.props."device.bus" == "bluetooth"))')" NAME="$(echo "$DEVICES" | jq -r 'map(.info.props."device.alias")[]')" NDEVS="$(echo "$NAME" | wc -l)" if [ "$NDEVS" -ne 1 ]; then echo "ERROR: there should be 1 device, found $NDEVS:\n" echo "${NAME}" exit 1 fi DEVID="$(pw-dump | jq -r ".[] | select(.info.props.\"device.alias\" == \"$NAME\").id")" PARAMS="$(pw-dump | jq -r ".[] | select(.info.props.\"device.alias\" == \"$NAME\").info.params")" CURPROFS="$(echo "$PARAMS" | jq -r '.Profile | map(.name) | .[]')" PROFILES="$(echo "$PARAMS" | jq -r ".EnumProfile | map(select(.available == \"yes\") | \"\(.priority)\t\(.index)\t\(.name)\") | .[]" | sort -rhk1)" BEST_A2DP="$(echo "$PROFILES" | grep -m1 a2dp)" BEST_HEADSET="$(echo "$PROFILES" | grep -m1 headset)" cat >&2 <