This file contains hidden or 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
repeat | |
set chargeState to do shell script "pmset -g batt | awk '{printf \"%s %s\\n\", $4,$5;exit}'" | |
set percentLeft to do shell script "pmset -g batt | egrep -ow '([0-9]{1,3})[%]' | egrep -ow '[0-9]{1,3}'" | |
considering numeric strings | |
if chargeState contains "Battery Power" and percentLeft ≤ 40 then | |
if (percentLeft mod 5 = 0) then | |
try | |
--say "Battery Low" | |
do shell script "afplay /System/Library/Sounds/Blow.aiff" | |
--display notification "Time to plug me in 🔌" with title "Battery Charge Boundary" sound name "Blow" |