[Pm-utils] pm-on-ac

Peter Jones pjones at redhat.com
Fri Apr 28 09:33:34 PDT 2006


On Fri, 2006-04-28 at 17:04 +0100, Richard Hughes wrote:
> In the spirit of making things simple, I'm suggesting porting
> on_ac_power (written in C) to bash, so the whole of pm-utils can be arch
> independent (no compiling).
> 
> The direct line-for-line conversion is attached, but please could
> someone review and correct my primitive sh.

Slightly smaller and faster:

#!/bin/bash

# Test if the computer is running on line power
# Exit status:
# - 0 (true)  System is on AC power
# - 1 (false) System is not on AC power
#
# NOTE: Absence of batteries is taken to mean that the system is on ac power.

# Check for AC/DC/etc adapters
for device in $(hal-find-by-capability --capability ac_adapter) ; do
        present=$(hal-get-property --udi $devices --key ac_adapter.present)
        [ "$present" == "true" ] && exit 0
done

#If there are no ac_adapters, check for batteries.
hal-find-by-capability --capability battery >/dev/null 2>&1 && exit 1

#If there are no batteries assume AC.
exit 0

-- 
  Peter



More information about the Pm-utils mailing list