12-05-2023, 10:21 AM
(This post was last modified: 12-05-2023, 10:22 AM by Kevin Kofler.)
Code:
if [ `qdbus-qt5 --system org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.OnBattery` == true ] ; then
echo on battery
else
echo plugged in
fi
You can also use dbus-send (with a slightly less user-friendly API), or scrape the upower --dump output.