@echo off title Battery Monitor - Full Focus Notifications & Louder Alerts :: Loop every…
- User
@echo off title Battery Monitor - Full Focus Notifications & Louder Alerts
:: Loop every 20 seconds :Start
:: Get battery percentage and charging status FOR /F "tokens=2 delims== skip=1" %%a IN ('wmic path Win32_Battery get EstimatedChargeRemaining /value') DO set batteryLevel=%%a FOR /F "tokens=2 delims== skip=1" %%a IN ('wmic path Win32_Battery get BatteryStatus /value') DO set batteryStatus=%%a
:: Remove spaces (important) set batteryLevel=%batteryLevel: =% set batteryStatus=%batteryStatus: =%
:: Show info in console echo Battery Level: %batteryLevel%%% - Status: %batteryStatus%
:: BatteryStatus Ref: :: 1 = Discharging (on battery) :: 2 = Charging :: 3 = Fully Charged :: 4 = Low :: 5 = Critical
:: -- LOW battery warning -- if %batteryLevel% LEQ 40 ( if "%batteryStatus%" NEQ "2" ( powershell -command ^ "player.PlayLooping();" ^ "wshell.Popup('Battery is %batteryLevel%%. Plug in the charger now!','0','LOW BATTERY WARNING ⚠️',48);" ^ "$player.Stop();" ) )
Assistant
Here's a modified version of your script that clears the console after each check to prevent messages from stacking up:
@echo off title Battery Monitor - Full Focus Notifications & Louder Alerts :: Loop every 20 seconds :Start cls :: Get battery percentage and charging status FOR /F "tokens=2 delims== skip=1" %%a IN ('wmic path Win32_Battery get EstimatedChargeRemaining /value') DO set batteryLevel=%%a FOR /F "tokens=2 delims== skip=1" %%a IN ('wmic path Win32_Battery get BatteryStatus /value') DO set batteryStatus=%%a :: Remove spaces (important) set batteryLevel=%batteryLevel: =% set batteryStatus=%batteryStatus: =% :: Show info in console echo Battery Level: %batteryLevel%%% - Status: %batteryStatus% echo. echo Monitoring... (Console will refresh in 20 seconds) echo. :: BatteryStatus Ref: :: 1 = Discharging (on battery) :: 2 = Charging :: 3 = Fully Charged :: 4 = Low :: 5 = Critical :: -- LOW battery warning -- if %batteryLevel% LEQ 40 ( if "%batteryStatus%" NEQ "2" ( powershell -command ^ "$player = New-Object System.Media.SoundPlayer 'C:\Windows\Media\Alarm10.wav';" ^ "$player.PlayLooping();" ^ "$wshell = New-Object -ComObject WScript.Shell;" ^ "$wshell.Popup('Battery is %batteryLevel%%. Plug in the charger now!','0','LOW BATTERY WARNING ⚠️',48);" ^ "$player.Stop();" ) ) :: -- CHARGING & NEARLY FULL warning -- if %batteryLevel% GEQ 95 ( if "%batteryStatus%"=="2" ( powershell -command ^ "$player = New-Object System.Media.SoundPlayer 'C:\Windows\Media\Alarm10.wav';" ^ "$player.PlayLooping();" ^ "$wshell = New-Object -ComObject WScript.Shell;" ^ "$wshell.Popup('Battery is %batteryLevel%% and still charging. Please unplug the charger.','0','BATTERY FULL ⚡',64);" ^ "$player.Stop();" ) ) :: Wait 20 seconds timeout /t 20 /nobreak > nul goto Start