This script provides a way to display battery alerts on MacOS using display-centered popups.
It could be configured as a LaunchAgent to run at user login or at specific intervals to monitor battery status and notify the user when the battery level is low or charged.
- discharging and drops below a threshold
- charging and reaches a target level.
- Display-centered popups for battery alerts
- Configurable battery level thresholds for alerts
- Easy to set up as a LaunchAgent
- Optional auto-dismiss feature for popups
It does not require any external dependencies, as it uses built-in MacOS tools like osascript for displaying popups.
- Copy the script to a desired location on your Mac.
- Make the script executable:
chmod +x /path/to/your/script.sh
- (Optional) Set up a LaunchAgent to run the script at login or specific intervals.
- Configure the battery level thresholds and auto-dismiss settings within the script as needed.
Open ~/bin/battery-alert.sh and tweak:
LOW_BATTERY=20 # notify when discharging at/below this % CHARGED_LEVEL=95 # notify when charging at/above this % POPUP_TIMEOUT=8 # seconds; set 0 to require manual close - Run the script manually or wait for the LaunchAgent to trigger it.
- Enjoy battery alerts displayed as popups on your Mac!
To create a LaunchAgent,
- Copy the file com.user.battery-alert.plist to ~/Library/LaunchAgents/
- Update the
ProgramArgumentspath to point to your script location. - Load the LaunchAgent:
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.user.batteryalert.plist
- Check the status:
launchctl list | grep batteryalert - Optional: The interval can be adjusted by editing the
StartIntervalkey in the plist file.