How do I automatically log the battery percentage and time on my Retina Macbook Pro to an excel spreadsheet? (OSX 10.9.4)

Hello! So I own a 13" rMBP, and I'm running OSX 10.9.4.


How do I log my battery percentage with the date, probably down to the hour, preferably to an Excel file?


I want to track the rate at which my battery discharges, so that in the future I can compare the present rate of discharge with the past and see exactly how much my battery has deteriorated by. I'll take averages over long periods of time to account for, e.g. the fact that watching Netflix drains my battery faster than editing an essay. I also want a solution that uses negligible power in the background.


I've spent hours looking for an app that both calculates the rate of discharge and keeps all data, but I haven't found any. Eventually I decided that hopefully it isn't too difficult to write an AppleScript or something that simply logs the system clock and battery percentage in tandem every hour or so.


Thank you for your time!

Herman

MacBook Pro with Retina display, OS X Mavericks (10.9.4)

Posted on Aug 9, 2014 12:04 PM

Reply
2 replies

Aug 9, 2014 2:48 PM in response to Tubung

Unless you also log the type of activity you are doing on the Mac at the time, the log you generate will be pretty useless.


The way I would tackle it would be to create either a shell script that you set to run hourly, or use an Automator Calandar Alarm, which you would then set up as an hourly event in Calendar. Shell script likely better.


Take a look at the Man page for pmset: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/ man1/pmset.1.html

pmset -g batt will give stats about the battery, and there are others that might give you more details, like pmset -g sysload

Aug 9, 2014 5:03 PM in response to Tubung

What Barney said.


Here is the script to create a CSV text file with

  1. Date
  2. Time
  3. Current Battery Percentage as an integer


#!/bin/bash

batterycsv="$HOME/battery.csv"



export GREP_OPTIONS="--color=never"

# if you want the percentage sign too, exclude the second egrep

battpct=$(pmset -g ps | egrep -o "(\d+)%" | egrep -o "\d+")

datetime=$(date "+%Y-%m-%d %H:%M")

printf "%s,%s,%s\n" $datetime $battpct >> $batterycsv


Output on a fully charged MacBook Air to battery.csv will be individual lines of the following format:


2014-08-09,19:49,100

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How do I automatically log the battery percentage and time on my Retina Macbook Pro to an excel spreadsheet? (OSX 10.9.4)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.