MacBuild Battery Test

From FreekiWiki
Revision as of 17:48, 11 September 2013 by AshleySueMas (talk | contribs) (→‎How to use it)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

---THIS SCRIPT IS NO LONGER IN USE---

Coconutbattery is used to determine battery capacity percentage

Lynnae 17:34, 21 June 2012 (UTC)


Code

#!/bin/bash
#macbuild battery test

BATFI=$HOME/bat_mon

if [ -f "$BATFI" ]; then
  MINZ=$(wc -l "$BATFI" | awk '{print $1}')
  echo "battery lasted $MINZ minutes"
else  
  while sleep 60; do
    echo "testing battery life!" | tee -a $BATFI
  done
fi

How it works

This script is pretty straightforward: when you run it on a system for the first time, it creates a file called "bat_mon" in the user's home directory, echoes "testing battery life!" in the terminal every 60 seconds, and appends the line to "bat_mon". Essentially each new "testing battery life!" line in "bat_mon" is equal to a minute of runtime. When you run this on a system the second time, the script will realize "bat_mon" already exists, count the lines in the file, and tell you how many minutes the battery lasted. Keep in mind that you will have to delete "bat_mon" if you want to run the script anew.

How to use it

You can either copy the code above and save it to [filename].sh (the name can be whatever you want, but make sure it ends in .sh) or download it from here.

Once you've got the script set up, go ahead and set up the system for the battery test (e.g. disable the screensaver, put an audio CD in the system's optical drive, set whatever media player to repeat, play the disc, and disconnect the system's power supply)

You then have to open up a terminal, navigate to the directory the file is in, and type:

oem@macbox:~$ sh [filename].sh

to start it, replacing [filename] with whatever you called it. Keep the terminal open while the script is running.

Once the system's battery has been drained, reconnect power to the system, power it on, navigate to the directory with the battery test script via the terminal, and run it again. It should see that "bat_mon" exists and tell you how long the battery lasted.