Macro to set MacBook Pro screen brightness to zero if brightness is beneath a certain threshold?

I generally keep my MBP attached to an external monitor. When I'm not using it and am just using the external monitor, which is roughly half the time, I prefer to turn the MBP screen off, i.e. set its brightness to zero, so that it's not distracting me.

The issue I'm having is that the MBP screen seems to turn back on ever so slightly on its own. This seems to be happening when the computer goes to sleep and wakes up. It only turns back on to like one level of brightness, but it's enough to be noticeable, and it's become annoying to have to regularly set the brightness back to zero.

I'd like to have a macro that checks my MBP screen brightness, say once every minute or five minutes. If the brightness is above 0% but beneath a certain threshold – say 10% – then the macro would set the MBP screen brightness back to 0%.

Any suggestions on how to do this? :pray:t3:

Can you try the following command in Terminal a couple of times at different brightness settings, and see if value changes?

ioreg -c AppleBacklightDisplay | grep -Eo "\"brightness\"[^}]+"

If so you should be able to extract the value, and if it's below a certain value (probably 6500), do the "Simulate Hardware Key - Brightness Down" action a few times.

1 Like

Thanks! I tried running this in Terminal, but nothing seems to happen. Is there something additional I need to be doing besides running the command in order to show the value?

This seems to be happening when the computer goes to sleep and wakes up. It only turns back on to like one level of brightness

As far as I'm aware this is the expected behaviour. You could make an Apple Shortcut to set the brightness to 0, and then have Keyboard Maestro execute that shortcut each time your MBP wakes up. You could also use Get Device Details in Shortcuts if you want to check what the brightness is first.

1 Like

@Nige_S' script shows a screen brightness values form 0 to 1024 on my Macbook Pro (Intel 2019, 16", Ventura), and this macro works for me:

Set screen brightness to 0 if bellow treshold .kmmacros (18 KB)

Macro Image

But it does not work on your system @alexcr?

1 Like

The command returns nothing for me on my desktop (Studio on Sonoma with two external displays), nor either of my laptops (MBP in Sonoma, MBA in some not yet released OS).


1 Like

The argument used can vary between OSs and maybe hardware -- what's your MacBook Pro running? I'll try and find the correct command.

Back home and on an M1 Air running Sonoma, where the correct command seems to be:

ioreg -rc AppleCLCD2 | grep IOMFBTestBacklightDimValue | grep -Eo "\d+$" a number from 0 for brightness at the minimum to 49152 for the maximum.

Hm, @Nige_S @Alexander. Still not working for me. My details...

MacBook Pro 16-inch, 2023
Chip Apple M2 Max
macOS Sonoma 14.5

Thanks, @hemicyon! Is there any way to set up a shortcut like this so that it's only running this on one of your two screens? (I'm my case, my MBP screen and not my external display.)

I'm fairly certain that the shortcut action setting the brightness level will only work on the built-in screen, so you should be good to go. I did have another thought, too, wherein the shortcut could also check for an external display, then only set the brightness to 0 if an external display is found.

Something like this:

1 Like

Thanks, @hemicyon! I'll give this a shot later this week, and will report back.

I won't be near a 16-inch MBP for a few days. But you could always try and find the correct string yourself, the way that I did.

Turn your brightness right down, open Terminal, type in

ioreg -c IORegistryEntry > ~/Desktop/ioreg1.txt

Turn brightness up to full, then in Terminal:

ioreg -c IORegistryEntry > ~/Desktop/ioreg2.txt
diff ~/Desktop/ioreg1.txt ~/Desktop/ioreg2.txt > ~/Desktop/diffFile.txt
open ~/Desktop/diffFile.txt

You can then scan the file in your text editor for lines that might be what you want, looking for lines that start with < and have a low value for something referencing "brightness", "display", or similar, immediately followed by a line starting with >, the same reference, and a high value.

The "key" for ioreg will be in the first line above those that starts with >, one or more |, and then +-o -- in my case that was

>     | |   | +-o AppleCLCD2  <class AppleCLCD2, id 0x100000377, registered...

...and the "key" is the string after "class": AppleCLCD2

Which is all a lot of faff, especially if this is so particular to OS and hardware and potentially liable to change! A better -- certainly easier! -- way to do what you want might be to:

  1. Make a macro that's simply repeat 4 times, press hardware key "Brightness Down", a periodic trigger set how you want, set the macro to disabled
  2. Make a macro for when you want the MBP screen off that's repeat 10 times, press hardware key "Brightness Down", enable macro from step 1, hot key trigger of your choice -- change the number of repeats to the max you'll ever need plus a couple for luck
  3. Make a macro for when you want the MBP screen on again that's repeat 7 times, press hardware key "Brightness Up", disable macro from step 1, hot key trigger of your choice -- change the number of repeats to suit your normal brightness setting

Then you can run your "go dark" macro whenever you want and the first macro will maintain that darkness until you run "go light".

1 Like

Sorry for the delayed follow-up, @hemicyon. I set up this shortcut more or less the same as you laid out, but when I run it, it's dimming both the MBP screen and my external display, instead of just dimming my MBP screen, which is what I wanted. Any idea what I might be doing wrong?

Behaviour will depend on monitor and connection -- most Apple displays respond to hardware key brightness changes, many third party ones don't.

So what display do you have, and how are you connecting?

1 Like

Finally got some time on one. So, in case helps anybody:

ioreg -rc IOMobileFramebufferShim | grep '\"IOMFBBrightnessLevel\"' | head -1 | grep -Eo "\d+$" a number from 0 (fully dimmed) to 19660800 (full brightness).

1 Like

Hm, yeah I'm not certain because when I tested it with my MBP and external monitor only the built-in display was affected, but it seems Shortcuts might be able to control some *external monitors. Unfortunately, I don't have any external displays by Apple, so I can't test it myself.

Looking again at the shortcut actions there doesn't appear to be a way to specify which display the brightness is set for—natively; however, there's an app I have called BetterDisplay that appears to have this functionality, which could maybe be worth looking at if all else fails. (Nb: Not sure if any of the shortcut actions are paywalled, but I don't have the paid version and do have access to the action to set brightness per display, though I'm not able to test its functionality at the moment.)

LG UltraFine 5K Display. Connected by Thunderbolt cable to my MacBook Pro.

Apple/LG partnered on that model, so not surprising it responds to the hardware keys. And I don't have that, or any external Apple displays, to test against.

Is it too late to suggest an external keyboard and mouse, and then you simply shut the laptop's lid when you don't want to be distracted by it? :wink: