MACRO: Brightness Control, v1.2


PURPOSE

The purpose of this macro is provide an easy method to switch between two adjustable Display Brightnesses: Dim and Bright

  • If the Primary Hot Key (⌃⌘B) is pressed, the Brightness will be toggled: Dim to Bright or vice versa

  • If the mac transitions from Charger to Battery, the Brightness will be set Dim.

  • If the mac transitions from Battery to Charger, the Brightness will be set Bright.

The Dim and Bright settings, ranging from 0 to 100, can be adjusted using a dialog that is displayed two ways:

  1. Using a Secondary Hot Key that includes ⌥(Option key). The default is: ⌃⌥⌘B

  2. Forcing a transition from Dim to Bright within 3 seconds of a transition from Bright to Dim. This can be done using the Primary Hot Key and/or power transitions.


SETTINGS

By default, during power transitions, this macro will change the Display Brightness as described above. Either or both transitions can be ignored using these settings:

local_BrightOnCharger : 1 = yes; 0 = ignore
local_DimOnBattery : 1 = yes; 0 = ignore

By default, a low volume sound, Sosumi, will be generated before the macro dialog is displayed. This can be disabled with the following setting:

local_DialogSoundAlert : 1 = yes; 0 = disable


IMPLEMENTATION NOTES

  • This macro uses native Keyboard Maestro actions to control the brightness. Since there is no action to set the brightness to a specific value—likely because macOS does not provide a Public API, it calculates the number of brightness increases from zero brightness and rapidly steps the brightness to the specified value (0 to 100).

  • This macro is a superset of Toggle Brightness, available here. If you downloaded that macro and plan to use this one, delete or disable Toggle Brightness as the two use the same Hot Keys. Toggle Brightness will no longer be updated.


TESTED WITH

• Keyboard Maestro 10.2
• Sonoma beta 14.1 (23B5067a)/MacBookPro16,1
• Mojave 10.14.16/Macmini6,2
• High Sierra 10.13.6/iMac11,1445


VERSION HISTORY

( expand / collapse )

1.0 - initial version

1.1
a) One of the two methods of displaying the adjustment dialog is by forcing a transition from Dim to Bright within 3 seconds of a transition from Bright to Dim. In this version this default time window was reduced from 10 to 3 seconds. This can be adusted using local_AutoDialogWindow.
b) Minor changes to the macro DESCRIPTION.

1.2
a) Add additional information to the dialogs.
b) Simplified the elapsed time calculation.
c) Persistent settings are saved to a dictionary rather than global variables.


Download: Brightness Control.kmmacros (100 KB)

Macro-Image


Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 14.1 (23B5067a) PRE-RELEASE SEED SOFTWARE
  • Keyboard Maestro v10.2

Note that this macro will automatically adjust the display brightness when transitioning* to a battery or to a charger.

* Either or both of these transitions can be ignored using macro settings. If you do have another macro that adjusts the display during that transitions, I suggest you disable all but one. It gets very confusing if two or more are concurrently enabled. (I speak from experience!)

3 Likes

I've updated the OP with Version 1.1 of Brightness Control:

  • One of the two methods of displaying the adjustment dialog is by forcing a transition from Dim to Bright within 3 seconds of a transition from Bright to Dim. In this version this default time window was reduced from 10 to 3 seconds. This can be adusted using local_AutoDialogWindow.

  • Minor changes to the macro DESCRIPTION.

2 Likes

Any way to define specific monitor in a multi-monitor setup?

I don’t know if Keyboard Maestro has the ability to control external monitors’ brightness/contrast. I have used a variety of other software for that over the years, and am using BetterDisplay for that right now.

2 Likes

Hi @mishamazor. I’m not sure. How do you adjust the brightness manually on your second monitor?

Wow BetterDisplay is amazing, thanks for the reco

2 Likes

You’re welcome.

@_jims sorry for hijacking your thread, it’s not my intention to detract from your macro in any way. :grin:

1 Like

Hi, @_jims. Thanks for sharing this macro. I have the same question as @mishamazor.

If you're using two displays, you can adjust the brightness for one or the other by going to Control Center and clicking on the ">" arrow that shows when you hover over the "Displays" section. Doing this takes you to an interface where you can adjust the brightness for one display or the other.

In any case, is there any way to adjust your macro so that you can get it to only act on one particular display?

For example, I'm regularly adjusting the brightness on my secondary display, my MacBook Pro. But I'm rarely adjusting the brightness on my primary display, which is a LG UltraFine 5K. So it would be great to use your macro, but so that it only operates on the MacBook Pro.

Hi, @alexcr. I'm sorry to say that I can't help here because I don't have a system with two or more monitors.

Maybe someone else on the forum will weigh in. Also, maybe this article will provide some valuable insight: Adjust External Display Brightness on Mac with MonitorControl

1 Like

No worries, @_jims! This article made me realize a very simple solution to this. For turning the secondary display on...

  1. Set current mouse location to a stored variable
  2. Move mouse 5,000 pixels to the left, to ensure it's on the secondary display
  3. Repeat the "Increase Screen Brightness" action 20 times
  4. Set mouse location to stored variable, so that it's returned to where you left off on the primary display

And then just duplicate this macro, but with "Decrease Screen Brightness," for turning the secondary display off. (I'm using one keyboard shortcut for one and a different one for the other. I imagine there's a way to set this up as a toggle, using the same shortcut for both, but I don't mind using two.)

1 Like

Hi, @alexcr. Glad you found a simple solution; and thanks also for sharing it here for the potential benefit of others.

1 Like

I've updated the OP with Version 1.2 of Brightness Control:

  • Add additional information to the dialogs.

  • Simplified the elapsed time calculation.

  • Persistent settings are saved to a dictionary rather than global variables.

1 Like