[Q} One brightness level for battery, one for plugged in?

Hey all,

I'm just switching over to KeyboardMaestro from Autohotkey on Windows and I really love the GUI. I've been able to work out so much of the stuff on my own, it's great!

One thing I'm struggling with is the 'The power status changes' trigger.

I'm trying to replicate something I had in Autohotkey:

When the charger is unplugged, screen brightness is set to 50%. 
When the charger is plugged in, screen brightness is set to 90%. 

At the moment, I've only been able to get random increases or decreases, because I don't fully understand the trigger.

Can anybody help a new user out? I'd be very grateful for any advice.

Thanks so much,


I don't think Keyboard Maestro has a way to set a specific display brightness, only increase it or decrease it relative to its current level.

Hmmm so would there be a way to achieve what I want? Say, decrease x 3 on unplug, increase x 3 on plug in?

Yea you can have it decrease it 16x so it goes to 0 and then increase it 5x or 12 x

How would I do that? I'm confused about the triggger.

It says 'The power status changes', so I'm not sure how to set up decrease on unplug and increase on plug in. I can only figure out how to make it go one way, if that makes sense.


I have looked at the TriggerValue of the trigger "Power status change".
And it seems 0 means on power and 1 on battery.

Combined with a commandline tool called Brightness, I was able to create the macro below, which works like you describe on my system.

Brightness Macro (v10.0.2)

Brightness.kmmacros (4.7 KB)

1 Like

Thanks so much for your help, I really appreciate it!

I've downloaded Brew and installed Brightness, but I can't find the ENV_PATH variable and I'm not sure where Homebrew installs bins on my system.

Sorry, this is only my third day with the OS so these are probably really stupid questions, but any help would be great

Hmm I think I've set my ENV_PATH to where Homebrew installs bins, but the script still isn't working/doing anything. What am I doing wrong?

Hmm.... you might want to double check that the path is correct by running this command in Terminal:

echo $PATH | sed 's/:/\n/g'

That will produce a list of anywhere custom scripts are installed. On my iMac it looks like this:


Copy those into your ENV_PATH variable separated by a colon. On my iMac it looks like this (there are extra paths because I also have Homebrew on my MacBook and use the same ENV_PATH variable for both machines):


Then try the macro again.

As @cdthomer writes your ENV_PATH should include all the paths from which you want to run shell scripts commands.
You could also reference the commands path directly in the Execute Shell Script action.
But first you need to find where brightness is installed.
You can use this command which brightness.
On my system it returns /usr/local/bin/brightness.
So the command could be /usr/local/bin/brightness 1

I prefer to add my paths to the ENV_PATH, so normally a command which works in the terminal works in KM.

Hi @HopelesslyConfused. (Nice username, BTW.) This won't specifically address the trigger issue you mentioned, but regarding the brightness adjustment, you could borrow some actions from this macro Toggle Brightness available here.

1 Like

Thanks for all the help. I used echo $path | sed 's/:\/n/g' to find all of the paths where scripts are installed, and then added it to my ENV_PATH variable, separated by colons.

Still no dice though. When I click the 'Settings Cog - Try Action' option under the brightness value actions in the script, nothing happens, so maybe there is a different problem?

At this point I'd recommend running some commands directly from Terminal to rule out a problem with the package.

If they run fine in Terminal, then turn on debugging in KM and rerun the macro to see where it fails.

Let us know how that goes and we can go from there.

Hopeless, it might also help if you upload a copy of your macro, so the team and double-check the logic.

1 Like

My copy of the macro is the same as the one @JimmyHartington posted.

However, I just opened terminal and typed 'brightness 1', and got the error:

brightness: failed to set brightness of display 0x1 (error -536870201)

So, it looks like the issue is with the Brightness commandline tool not working on my Mac? I've got an M1 Macbook Air if that makes any difference

Do you have any external monitor connected?
And which version of macOS are you on?

Nope, no external monitors connected.

I'm on macOS Monterey Version 12.1

It seems the version in Homebrew of Brightness is not updated to M1 Macs: https://github.com/nriley/brightness/issues/38

So to use Brightness it seems you need to install it from source.
The instructions below is taken from the github page for the project.
I have never installed anything like this from source, so I do not know where the command gets installed.

Install From Source

git clone https://github.com/nriley/brightness.git
cd brightness
sudo make install

Hmm, that didn't work either, but I did manage to modify the macro posted by @_jims to work with the changed power state setting. If anyone else wants to use it, here it is! You can change your dim setting and bright setting by hitting Option-Command-H.

Thanks for everyone's help!

Charger Brightness Change.kmmacros (19.9 KB)

Hi @HopelesslyConfused, I decided to start with Toggle Brightness and create a new macro with several enhancements including automatic adjustment for power transitions: Charger to Battery and vice versa.

I recommend you use the new macro as it likely has some other features you will find useful. In addition it has been much more thoroughly tested. Frankly, Toggle Brightness was slapped together and had a few rough edges. I've officially declared it superseded in the thread where it was posted.

I've posted the new macro in a seperate thread: Brightness Control