From d04260976c6bab27589be3a490d64172cdc2bc99 Mon Sep 17 00:00:00 2001 From: dbroqua Date: Mon, 2 Nov 2020 09:21:47 +0100 Subject: [PATCH] Added bt status script --- Bin/bluetooth_headphones_status.sh | 46 ++++++++++++++++++++++++++++++ Bin/bt_dev_info.awk | 16 +++++++++++ 2 files changed, 62 insertions(+) create mode 100755 Bin/bluetooth_headphones_status.sh create mode 100755 Bin/bt_dev_info.awk diff --git a/Bin/bluetooth_headphones_status.sh b/Bin/bluetooth_headphones_status.sh new file mode 100755 index 0000000..7ecb9ac --- /dev/null +++ b/Bin/bluetooth_headphones_status.sh @@ -0,0 +1,46 @@ +#!/bin/zsh +DIR=$(dirname $0) +CMD=$1 + +# Get the first bluetooth device info +# This comes as a CSV +BT_SINK=$(pacmd list-cards | $DIR/bt_dev_info.awk | grep "bluez" | head -n 1) + +if [ ! -z ${BT_SINK} ]; then + # if there is a device connected, then we can either list or change profile + # otherwise we do nothing + id=$(echo ${BT_SINK} | cut -d "," -f 1) + current_profile=$(echo ${BT_SINK} | cut -d "," -f 4) + case ${current_profile} in + "") + icon="headphones" + next_profile="headset_head_unit" + ;; + "") + icon="phone" + next_profile="a2dp_sink" + ;; + *) + icon="unknown" + next_profile="" + ;; + esac + case $CMD in + "toggle_profile") + pacmd set-card-profile ${id} ${next_profile} + ;; + *) + case ${current_profile} in + "") + echo "" + ;; + "") + echo "" + ;; + *) + echo "-" + ;; + esac + ;; + esac +fi diff --git a/Bin/bt_dev_info.awk b/Bin/bt_dev_info.awk new file mode 100755 index 0000000..33cd8d7 --- /dev/null +++ b/Bin/bt_dev_info.awk @@ -0,0 +1,16 @@ +#!/usr/bin/awk -f +BEGIN { + FS = "([ ]?:[ ])|([ ]=[ ])"; + print "INDEX,NICE_NAME,DEVICE,ACTIVE_PROFILE" + count = 0; +} +/index/ { i=$2; indices[count++] = $2 } +/^\s+name:/ { names[i] = $2 } +/^\s+active profile:/ { profiles[i] = $2 } +/^\s+device\.description/ { nice[i] = $2 } +END { + for (j=0; j