- Add
battery.monitor.plistto~/Library/LaunchAgents - Modify
~/Library/LaunchAgentsto point to path ofBatteryStatusNotification.scpt
Last active
June 28, 2022 09:37
-
-
Save ariefrahmansyah/32b493ed4f6b1dc4679896a2d81abf55 to your computer and use it in GitHub Desktop.
Mac's Battery Status Notification
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
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| <plist version="1.0"> | |
| <dict> | |
| <key>Label</key> | |
| <string>battery-status-monitor.job</string> | |
| <key>ProgramArguments</key> | |
| <array> | |
| <string>/usr/bin/osascript</string> | |
| <string>BatteryStatusNotification.scpt</string> | |
| </array> | |
| <key>RunAtLoad</key> | |
| <true/> | |
| </dict> | |
| </plist> |
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 ≤ 20 then | |
| display notification "Time to plug me in 🔌" with title "Battery Charge Boundary" sound name "Ping" | |
| #else if chargeState contains "AC Power" and percentLeft ≥ 80 then | |
| # display notification "Time to unplug me 🔋" with title "Battery Charge Boundary" sound name "Ping" | |
| end if | |
| end considering | |
| delay 300 | |
| end repeat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment