3

I unchecked "Show battery status in menu bar" in System Preferences > Energy Saver, because I use coconutBattery instead (and obviously I don't want to just re-check that).

But this means that now my MacBook doesn't alert me when the battery is getting low and just drains itself to 0% then dies on me.

I want to make an automatic AppleScript/cron job/whatever to alert me when the battery is less than 50%, and again when it's less than 20%.

How can I do that?

6
  • applehelpwriter.com/2014/08/25/…
    – anki
    Commented Apr 15, 2019 at 17:17
  • 1
    In System Preferences under Energy Saver, is the "Show battery status in menu bar" check box checked? If not, then check it. If it is checked and you do not get any low battery warning, then there is something wrong with the system process that monitors it. That said, any script type of solution is probably going to be resource heavy having to constantly check the state of the battery charge. I'd opt for fixing the real issue, otherwise see if some third party app is available to monitor it and pass a warning, as it would probably be more effective resource wise then a script. Commented Apr 15, 2019 at 17:23
  • This sounds like your battery is failing and the issue is at a particular moment in time it has sufficient charge, but then "hits" a dead cell and the charge falls immediately causing it to power off. See this answer
    – Allan
    Commented Apr 15, 2019 at 18:01
  • @user3439894 it is not checked
    – user150109
    Commented Apr 15, 2019 at 20:59
  • Also see: apple.stackexchange.com/a/325339/119271
    – Allan
    Commented Apr 15, 2019 at 21:52

2 Answers 2

2

I had the same issue when I use a Bitbar plugin on OSX and have the default battery menubar unchecked. Here is what I use in my shell script to include a osascript call to create a notification pop up.

# Get info
power_source=( $(pmset -g batt | awk 'FNR == 1 {print $4$NF}' ) )
battery_level=( $(pmset -g batt | awk -F"\t" 'FNR == 2 {print $2}' | grep -o '[0-9]\+' ) )

# Notification when battery level is low
if [ "$power_source" != "'ACPower'" ] && [ "$battery_level" -le 5 ]; then osascript -e 'display notification "️⚠️ LOW POWER! ⚡" with title "Battery"';
fi

You could use this as a cron job. =)

1

There areo several free apps on the app store that will display your battery info and send notifications for certain levels of you battery. You should probably check there first and search on battery. Some options are "Battery Health 2" and "Battery Monitor"

There is a paid app named "Battery Charging Alert" which will do what you want. It will send you notifications when battery level is under some preset value. It puts a small window on your desktop with battery level info. The app is $5 from the App Store.

You must log in to answer this question.