Linux Mint. Checking Battery Status

Linux Mint does not come with battery watcher. It is a bit annoying when your laptop shuts down, all because you have forgotter to plug it in.

After a bit of research found out this small bash script which does exactly what I wanted.

The script will watch the battery and will notify you once it goes under a specified percentage

 

#!/bin/bash

DEBUG:

notify-send " Listening for battery status " -t 8000

Set the alert tone for battery, or leave it as empty quotes.

.mp3 or .ogg audio file

alarm="/your/path/battery_notification.ogg"

Notify when below this percentage

warning_level=70

How often to check battery status, in minutes

check_interval=2

 

while true; do

  battery_level=$(acpi -b \

    | cut -d, -f2 | cut --characters=2,3,4 \

    | sed 's/%//g')

  charging=$(acpi -b | grep -c "Charging")

 

  # When battery is low, and not already charging

  if [ $battery_level -lt $warning_level ] &&

     [ $charging -eq 0 ]

  then

    play -q -v 0.40 "$alarm" &

    notify-send " Low battery: ${battery_level}% " \

      " Plug into mains power " -t 8000

  fi

 

  sleep ${check_interval}m

done

 

So how to install it on Linux Mint.

  1. Copy the script and paste it in a file called battery_status.sh

  2. Open "Startup Applications" from your main menu

  3. Using the "Browse" button select your file

  4. Give it a delay of say 30 seconds, and save

The next time you restart your Linux Mint, you will get a nice notification once the battery starts to dwindle,

Loading blog_post_recommendations...