Battery Uptime Usage for Macbook Air

macrumors member

I have created a very simple Applescript to help me analyze battery uptime usage for my new 2012 11" i7/8/256 Air running ML.

I wanted to confirm my battery uptime and thought others might be interested in doing the same. The script refreshes any website over and over again automatically. For my test I have set the screen brightness at 50% and keyboard backlight about 20%, no bluetooth, running ML.

1) Make sure you Macbook is fully charged (100%) and you have setup energy saver so that the computer and display never sleep for this test.

4) Copy Applescript (below) to Applescript Editor (you can find this undder Utilities) under and click RUN. I have a youtube video setup to refresh every 60 seconds. Feel free to update this to any youtube or automatic streaming URL and you can change the delay time.

5) Every 60 seconds "Uptime log.txt" (written to the desktop) will be updated with the current date time and the battery level at that time.

6) Let your macbook run until the battery is exhausted

7) Now when the macbook restarts you can view the output file and calculate the time difference from the first entry and the last to get you uptime.

Here's the Applescript I am using (cut and paste this to your Applescript Editor)
--------------------------------------------------------------------------------------------
repeat

-- Insert any URL as desired
open location "http://www.youtube.com/watch?v=AcLCfUutnnI"

-- Set any delay to a desired value. Every 60 seconds the file Uptime log.txt will be updated
delay 60

set thePath to (path to desktop as Unicode text) & "Uptime log.txt"

set fRef to (open for access file thePath with write permission)
try
set myDate to date string of (current date)
set myTime to time string of (current date)
set myDatetime to myTime & " " & myDate
write myDatetime to fRef starting at eof

set maxCapacity to do shell script "ioreg -w0 -l | grep \"\\\"MaxCapacity\\\" =\""
set maxLevel to the last word of maxCapacity
set curCapacity to do shell script "ioreg -w0 -l | grep \"\\\"CurrentCapacity\\\" = \""
set curLevel to the last word of curCapacity
set battPct to round (100 * curLevel / maxLevel)
set output to " : Battery " & battPct & "%"
write output & return to fRef starting at eof

end try
close access fRef

end repeat
--------------------------------------------------------------------------------------------

MacRumors attracts a broad audience
of both consumers and professionals interested in
the latest technologies and products. We also boast an active community focused on
purchasing decisions and technical aspects of the iPhone, iPod, iPad, and Mac platforms.