Skip to content

Instantly share code, notes, and snippets.

@xu-chris
Last active January 29, 2018 21:23
Show Gist options
  • Save xu-chris/fc3b0306bb89c11e0b24 to your computer and use it in GitHub Desktop.
Save xu-chris/fc3b0306bb89c11e0b24 to your computer and use it in GitHub Desktop.
Return true when Mac battery percentage is under 10 percent
#!/bin/sh
# Use this shell script in combination with ControlPlane (http://www.controlplaneapp.com) to detect
# and automatize when the battery percentage is lower or equal than 10 percent.
# For example: let ControlPlane close for you all Cloud applications when you to low battery life.
batteryPercentage=`pmset -g batt | egrep -ow '([0-9]{1,3})[^%]'`
lowbatPercentage=10
if [ ${batteryPercentage} -le ${lowbatPercentage} ]; then
exit 0
else
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment