Re: [dwm] Proper way of monitoring battery level in DWM

From: Riccardo Murri <riccardo.murri_AT_gmail.com>
Date: Sun, 16 Sep 2007 23:03:17 +0200

On 9/16/07, Amit <amit.uttam_AT_gmail.com> wrote:
> Actually right now, I am using apm. I am not sure if acpi is supported
> on my notebook. This is an old PowerBook G4 500MHz. I will try
> modifying the scripts to use apm instead of acpi.
>

If it's a PowerBook G4, then it's using PMU, not ACPI nor APM.

Under GNU/Linux, you can use the command `pbbcmd` to query the battery status::

  $ pbbcmd query powersource
  0 # <-- outputs "0" if running on battery, and "1" if running on AC power.
::

  $ pbbcmd query timeremaining
  8760 # <-- remaining running time in seconds.

Or you can directly parse the /proc/pmu/battery_0 file::

  $ cat /proc/pmu/battery_0
  flags : 00000011
  charge : 3251
  max_charge : 3251
  current : -1334
  voltage : 12613
  time rem. : 8773

For instance you could define a `battstat` command::

  #! /bin/sh
  if [ -r /proc/pmu/battery_0 ]; then
    sed -e 's/ *: */ /' /proc/pmu/battery_0 | ( \
       while read key value; do
         case "$key" in
            "charge") charge="$value";;
            "max_charge") max_charge="$value";;
            "current") if [ "$value" -eq 0 ]; then on_ac_power=yes; fi;;
         esac
      done
      if [ -z "$on_ac_power" ]; then
        echo "batt:$(expr $charge \* 100 / $max_charge )%"
      else
        echo "(AC)"
      fi
    )
  fi

And then invoke dwm like::

  (while sleep 10; do battstat; done) | dwm

 Riccardo
Received on Sun Sep 16 2007 - 23:03:19 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 14:53:25 UTC