Out of the Darkness Comes Light

One topic I’ll probably be writing about a lot is batteries. I believe I may be a bit obsessed about the matter. I keep my devices charged whenever possible. I’m constantly aware they are living on borrowed time.

I recently switched back from using MacBook Pros to Windows 10 on a Dell XPS. I found out Microsoft removed the option to automatically dim your screen on battery. Since I haven’t used Windows in a while, this was a surprise to me.

I started dimming the screen manually every time I unplugged my laptop. Then setting the brightness back up when plugging in. This did not always work for me. Sometimes I forgot to do it. The rest of the times just felt… Repetitive.

So I thought to myself – surely this could be automated. I did a little bit of digging. Guess what – it CAN be. I’ll save you the trouble of investigating this yourself. You will need a little (very little, I promise) technical knowledge.

  1. Download NirCmd. You probably want the 64 bit version. You can use another command line tool that can toggle the screen brightness if you prefer.
  2. Move the NirCmd files to C:\Program Files\nircmd.
  3. In that folder, create a new text file and name it DimScreenToggle.bat.
  4. Open the new file in NotePad or your favorite editor, and paste the following into it:
@echo off
set DimScreen=""c:\Program Files\nircmd\nircmd.exe" setbrightness 0"
set UndimScreen=""c:\Program Files\nircmd\nircmd.exe" setbrightness 100"
set Scr="%temp%\DimScreenToggler.vbs"
set VB=echo^>^>%Scr%
if exist %Scr% del %Scr%
%VB% Set oWMIService = GetObject("winmgmts:\\.\root\CIMV2")
%VB% Set cItems = oWMIService.ExecQuery("SELECT * FROM Win32_Battery")
%VB% For Each oItem In cItems
%VB% iStatus = oItem.BatteryStatus
%VB% if iStatus = 1 then WScript.echo "On battery" Else WScript.Echo "Mains operation"
%VB% WScript.quit iStatus
%VB% Next
cscript //nologo %Scr%
IF %ErrorLevel% EQU 1 (start /b "Dim Screen" "%DimScreen%") ELSE (start /b "Undim Screen" "%UndimScreen%")

The above creates a script that checks the power source and sets the screen brightness accordingly: to 0 if on battery, or to 100 if plugged in. You can adjust these numbers to fit your preference.

  1. Save the file.
  2. Launch your Event Viewer (Windows Key + R, then type in eventvwr, and click OK.).
  3. On the left of the Event Viewer window, expand Windows Logs and then System.
  4. Next, unplug your laptop. Wait for a second or two, and plug it back in.
  5. From the menu, select Action -> Refresh. You should see two new events at the top. Note the Event ID.
  6. Right click on one of the two events, and then on Attach Task To This Event.
  7. In the new Create Basic Task Wizard window, fill in a name for your task (Toggle screen brightness by power source would work). Click Next.
  8. Click Next again on the following screen (When an event is Logged).
  9. In Action, keep the selection on Start a program. Click Next.
  10. Click Browse, then find the DimScreenToggle.bat file you created earlier. Select it and click Open.
  11. Leave the rest as is, and click Next.
  12. Tick the Open the Properties dialog for this task when I click Finish checkbox. Click Finish.
  13. In the properties window that opened, go to the Triggers tab.
  14. Click on New… to add a new trigger.
  15. In the Begin the task dropdown, select At startup.
  16. Tick Delay task for, and set the time to 5 seconds.
  17. Click OK to dismiss the new trigger window.
  18. Under Conditions, make sure Start the task only if the computer is on AC power is unticked.
  19. Click OK to dismiss the properties window. You’re done!

To test your new setup, try unplugging your laptop. It should dim the screen almost immediately. Plug it back in to see the screen brighten up.

With this setup, expect a significant boost to your battery life. Let there be light!

Published by eranboudjnah

A software consultant and tech lead. Passionate about optimizing as many aspects of my life as possible, to free time for what really matters.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: