Added bt status script

This commit is contained in:
dbroqua 2020-11-02 09:21:47 +01:00
parent 2ff1814560
commit d04260976c
2 changed files with 62 additions and 0 deletions

View file

@ -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
"<a2dp_sink>")
icon="headphones"
next_profile="headset_head_unit"
;;
"<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
"<a2dp_sink>")
echo ""
;;
"<headset_head_unit>")
echo ""
;;
*)
echo "-"
;;
esac
;;
esac
fi

16
Bin/bt_dev_info.awk Executable file
View file

@ -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<count; j++) {
i=indices[j];
print i "," nice[i] "," names[i] "," profiles[i]
}
}