From 662eac4d7bcad76b657c2621f9cd11c97e4d15d3 Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Tue, 16 Apr 2024 18:46:45 +0200 Subject: pw-prof: toggle between pipewire profiles --- pw-prof | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 pw-prof diff --git a/pw-prof b/pw-prof new file mode 100755 index 0000000..82ab6d9 --- /dev/null +++ b/pw-prof @@ -0,0 +1,75 @@ +#!/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 <