#! /usr/bin/env sh # When battery has less than 25%, pops up notifier counting down integer % of battery left 24, 23, 22, 21 ... # When battery is less than 15% also announces "Low Battery" verbal warning. # INSTALL: Put this powerchange.sh file in /Users/Shared/ folder on your mac laptop, then chmod a+x *.sh # And put com.me.powerchange.plist (below) in ~/Library/LaunchAgents/ (or /Library/LaunchAgents/ for every user). # This file is run by com.me.powerchange.plist whenever charger is disconnected # When charger is unplugged, the date of this file changes: Library/Preferences/com.apple.powerlogd.plist ## https://stackoverflow.com/questions/14108471/launchd-watchpaths-will-not-trigger-simple-hello-world-script-os-x-10-8 ## See also https://github.com/Goles/Battery/ export PWRINFO=$(ioreg -l | grep ExternalConnected) export BATT_PCT=$(pmset -g batt | grep -o '[0-9]*%' | tr -d %) echo -e $PWRINFO ' \t' " % " $BATT_PCT | logger -i -t batmom -s 2>> /var/log/batmon.log if [[ $BATT_PCT -lt 25 ]]; then echo $PWRINFO $BATT_PCT "%" | /usr/local/bin/terminal-notifier if [[ $BATT_PCT -lt 15 ]]; then echo "Low Battery " $BATT_PCT "%" | say fi fi #echo $PWRINFO $BATT_PCT "%" exit 0