Perl / Applescript to check remaining Powerbook Juice

Here is a little perl / applescript I put together that monitors the status of my battery level. When the battery gets to a low enough threshold, an alert prompt is displayed so I know that it's time to start thinking about plugging the computer back in. This idea started after reading this hint.

You will see my comments if you scroll down (look for kb5ql).

To proceed, you will need to perform the following steps:

1. download and install the battery_check_alert script
2. change the permissions on the downloaded file
3. update your crontab entry to regularly run the script

-->

  1. Download battery_check_alert.pl
  2. Move the file to your home directory /Users/<your_username>/
  3. Launch the Terminal application (/Applications/Utilities/Terminal)
  4. I recommend changing the name of the file from 'battery_check_alert' to '.battery_check_alert' (single quotes added). Files that start with a period '.' are hidden from view in the Finder.

    In order to change the filename, you will need to type in the following command: mv /Users/<your_username>/battery_check_alert.pl /Users/<your_username>/.battery_check_alert

  5. Next, you will need to install a cron job. If you don't know how to do this, simply copy the code below:

    */4 * * * * perl /Users/<your_username>/.battery_check_alert 8 > /tmp/batt.log 2>&1
    */30 * * * * perl /Users/<your_username>/.battery_check_alert 40 > /tmp/batt.log 2>&1

  6. Lastly, just to be safe, you will need to grant execute permissions on the file. Run the following command:

    chmod 755 /Users/<your_username>/.battery_check_alert

You have now installed the script. The cron job runs at 2 separate intervals. Every 4 minutes the computer checks to make sure that your battery is greater than 8 percent capacity. Every 30 minutes it checks to see if the battery has more than 40 percent left. If the levels fall below this, an alert is displayed.

I have been running this script for approximately two years with no percepitible performance hit. Also, it (should) stop execution immediately if it detects that the powerbook is plugged in already.

zaftig defined

zaftig |ˈzäftig; -tik| (also zoftig)
adjective informal
(of a woman) having a full, rounded figure; plump.
ORIGIN 1930s: Yiddish, from German saftig ‘juicy.’

Featured Gallery

Sites I Like