#!/usr/bin/perl -w
my $MaxCapacity = `ioreg -l | grep 'MaxCapacity'`;
my $CurrentCapacity = `ioreg -l | grep 'CurrentCapacity'`;
$MaxCapacity =~ /(\d+)/;
$MaxCapacity = $1;
$CurrentCapacity =~ /(\d+)/;
$CurrentCapacity = $1;
printf("Battery Charge: %d %%" . "\n", (($CurrentCapacity / $MaxCapacity) * 100));
Executing the script produces something similar to:
Battery Charge: 90 %
If you execute this on a Mac that doesn't have a battery you will probably get a division by zero error.
No comments:
Post a Comment