Battery status script

Edit 7.3.2025: More graphical script with upower check

Battery_info2.zip

#!/bin/bash
#
# RJP 5.3.2025 Battery info script
# Packages YAD and UPOWER must be installed
# 6.3.2025 install upower package dialog added if upower is not installed.
inxi -B > /tmp/battery0.txt
#
cat /tmp/battery0.txt | awk '{print $2}' > /tmp/battery.txt
#
sed -i 1d /tmp/battery.txt
# Check if upower exists
if [ ! -f /usr/bin/upower ]
then
yad --width=500 --text-align=center --center --title=$"INSTALL UPOWER PACKAGE" --text="INFO

You need to install upower package , so that you can run this script

Do you want to install upower?"
if [ $? = 0 ];
then
x-terminal-emulator -e /bin/bash -c "sudo apt update && sudo apt install upower && \
echo #######
echo #######
read -p \"You can close this window\""
fi
else

/bin/bash -c "upower -i /org/freedesktop/UPower/devices/battery_$(cat /tmp/battery.txt)" > /tmp/batteryinfo.txt

yad --width=500 --text-align=center --center --title=$"BATTERY INFO" --text="BATTERY INFO

$(cat /tmp/batteryinfo.txt)"
fi

If upower is not installed

########################

Xterm package must be installed and replace BAT0 with correct device.

The script:

#!/bin/sh
xterm -e 'echo #################
echo Checking battery status
echo #################
upower -i /org/freedesktop/UPower/devices/battery_BAT0
echo #################
echo Close the scipt pressing Ctrl c
sleep 900'
exit 0