MichalW / gnome-bluetooth-battery-indicator

Gnome-Shell extension displaying battery percentage for bluetooth devices
GNU General Public License v3.0
118 stars 39 forks source link

Ubuntu Jimmy-Jellyfish run using PulseAudio log (Gnome 42). #43

Open kred-jon opened 2 years ago

kred-jon commented 2 years ago

Hi, I able to have the percentage run make use of pulseaudio log after make edit the scripts/Upower.sh as below:

#!/bin/bash

# awk explaination: https://stackoverflow.com/questions/13534306/how-can-i-set-the-grep-after-context-to-be-until-the-next-blank-line
# grep explaination: https://stackoverflow.com/questions/1546711/can-grep-show-only-words-that-match-search-pattern
#percent=$(upower --dump | tr '[:lower:]' '[:upper:]' | awk "/$1/" RS= | grep -oE '[0-9]{1,3}%')
connected=$(bluetoothctl info $1 | grep "Connected" | cut -d ' ' -f2)
#replace percent to run from syslog pulseaudio
percent=$(more /var/log/syslog |grep Battery |tail -1 |cut -d ' ' -f9)  

if [[ $connected == "yes" ]]; then
  if [ -z "$percent" ]; then
    echo "?"
  else
    #echo "$percent"
    echo "$percent"
  fi
elif [[ $connected == "no" ]]; then
  echo "off"
else
  echo "?"
fi

image

kred-jon commented 2 years ago

update the code.

7 percent=$(more /var/log/syslog |grep "Battery Level" |tail -1 |cut -b 60-65)