Beep Alert when Battery is below 10% — MacOS.

Narendra Sisodiya
1 min readAug 1, 2021

My MacBook shut down most of the time because I am working and lazy to put the charger in.

It shows a notification at 10% battery but I usually forget.

How about a irritating Beep sound which start when battery is below 10%

Beep

Save the following script somewhere — You can download it from https://raw.githubusercontent.com/nsisodiya/ubuntu-battery-alarm/master/mac/mac-battery-alarm-service.sh too

#!/bin/bash
while true;
do
echo ""
charging_level=$(pmset -g batt | grep -Eo "\d+%" | cut -d% -f1)
charging_status=$(pmset -g batt | grep charging | cut -f4 -d" " | cut -f1 -d ";")
echo "Cuttent charing level is $charging_level and Battery is $charging_status"
if [ "$charging_status" == "discharging" ];then
if (( charging_level < 10 )); then
echo "Battery is LOW and Less than 10% & Discharging"
#amixer set 'Master' 100%
afplay /System/Library/Sounds/Blow.aiff
fi
fi

if (( charging_level < 5 )); then
sleep 2;
else
sleep 5;
fi
done

This script basically checks the battery level and plays the beep sound.

and you can use “Automator” in the macOS to run this shell script.

Check here.

--

--