Created
January 16, 2021 05:26
-
-
Save dukechem/c6e59c3b6b2b0c86acb426fd27d0510e to your computer and use it in GitHub Desktop.
Low battery warning by audio and notification for macos laptops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copy code below line to com.me.powerchange.plist file. Put file in ~/Library/LaunchAgents/ folder