aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillermo Ramos2024-04-16 18:46:45 +0200
committerGuillermo Ramos2024-04-16 18:46:45 +0200
commit662eac4d7bcad76b657c2621f9cd11c97e4d15d3 (patch)
tree4aa43b0c00cfcc271c62638f5fc6a3ceadf96a3a
parent093ef9ec9c0b7a95f756bab33299dada50d087f4 (diff)
downloadcli-662eac4d7bcad76b657c2621f9cd11c97e4d15d3.tar.gz
pw-prof: toggle between pipewire profiles
-rwxr-xr-xpw-prof75
1 files changed, 75 insertions, 0 deletions
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 <<EOF
+NAME: $NAME
+DEVID: $DEVID
+CURPROF: $CURPROFS
+
+PROFILES:
+prio idx name
+$PROFILES
+
+BEST PROFILES:
+prio idx name
+$BEST_A2DP
+$BEST_HEADSET
+
+EOF
+
+usage() {
+ echo "Usage: $0 {cycle|a2dp|headset}"
+ exit 0
+}
+
+case "$1" in
+ cycle)
+ if echo "$CURPROFS" | grep -iq a2dp; then
+ newprof=headset
+ else
+ newprof=a2dp
+ fi
+ ;;
+ a2dp)
+ newprof=a2dp;;
+ headset)
+ newprof=headset;;
+ *)
+ usage
+ ;;
+esac
+
+if [ "$newprof" = "headset" ]; then
+ newprofidx="$(echo "$BEST_HEADSET" | cut -f2)"
+ newprofname="$(echo "$BEST_HEADSET" | cut -f3)"
+elif [ "$newprof" = "a2dp" ]; then
+ newprofidx="$(echo "$BEST_A2DP" | cut -f2)"
+ newprofname="$(echo "$BEST_A2DP" | cut -f3)"
+fi
+
+echo "[$NAME] Setting profile to '$newprofname' (idx $newprofidx)..."
+
+wpctl set-profile "$DEVID" "$newprofidx"