Keyboard Shortcut for Display Brightness

So I’m running an Acer C740 and I’m contemplating nuking my ChromeOS install and going with MATE. I really like it so far (have it installed to a USB).

The one thing I’m having a problem with is not being able to change the brightness without going to display setting and manually moving the slider.

I attempted the suggestion from the Ubuntu forum but to no avail. When I ran the program from the command line it said I didn’t have any hardware that had a backlight.

Do you have any suggestions for me?

Thanks for your help!

So, after looking for an answer for a while…

pkexec mate-power-backlight-helper --get-brightness

This will give you the current value for brightness, execute the command when at max brightness to know what the upper bound is.
Then once you know the max:

pkexec mate-power-backlight-helper --set-brightness [0-MAX]

On my laptop to get a very dim screen:

pkexec mate-power-backlight-helper --set-brightness 10

It occurs to me I only answered half the question.

#! /usr/bin/env python3

from subprocess import check_output, call
import argparse as ap

p = ap.ArgumentParser()
p.add_argument("direction", choices = ["+", "-"])
args = p.parse_args()

MAXBRIGHTNESS = 4000 # TODO: UPDATE THIS
STEP = MAXBRIGHTNESS / 10 # We want 10-percent increments

# Get current brightness value
current = check_output(
            "pkexec mate-power-backlight-helper --get-brightness",
            shell = True
          )

# Update brightness value
current = float(current)
new = current
if args.direction == "+":
    new += STEP
else:
    new -= STEP

# Prevent (under/over)flow of new value
if new < 0:
    new = 0
elif new > MAXBRIGHTNESS:
    new = MAXBRIGHTNESS

# Update brightness
call(
    "pkexec mate-power-backlight-helper --set-brightness " + str(int(new)),
    shell = True
)

Save this code into a file, for instance in your home folder in a subfolder named "bin" and with the name "modbrightness.py" and edit inside the file the value for MAXBRIGHTNESS with the one you got previously.
Note: you can also edit the STEP value if you feel a 10% increment is too little.

[email protected]:~/Desktop$ ls ~/bin/modbrightness.py 
/home/ouroumov/bin/modbrightness.py
[email protected]:~/Desktop$ 

Make it executable using the command:

chmod +x ~/bin/modbrightness.py

Then go to keyboard shortcut preferences, and create a new shortcut (click add):

Note: you have to give the full path to the file including the "/home/your_username" part.

Then define the key combination you want:

(click 'Disabled')

4 Likes

You. Are. Amazing!

Thank you so much. As soon as I get back there I’ll give it a shot. You should totally send this upstream. Having a setting like this built into the DE would be a great addition for everone with a laptop.

I can’t believe you wrote a python script for me. That’s awesome. I’m learning python right now, so I’ll go through it line by line.

Thanks again!

Zack

Lol, wait and see if it works before sending the cookies. ^^"
I’ve only tested the thing on my notebook.
Also please note that key combination CTRL+SHIFT++ I used will conflict with the “Zoom” shortcuts (like in the terminal) if you haven’t changed them, so I recommend you test using another combination.

It works! I’ve got about 3 points between black (off) and full, but I can play with the script and see if there’s some room for more granulation.

You are awesome. Thanks again!

2 Likes

So I changed MaxBrightness to 1000 from 4000 and now I have 10 increments. Here is the new code all written by ouroumov except for one character change:

#! /usr/bin/env python3

from subprocess import check_output, call
import argparse as ap

p = ap.ArgumentParser()
p.add_argument("direction", choices = ["+", "-"])
args = p.parse_args()

MAXBRIGHTNESS = 1000 # TODO: UPDATE THIS
STEP = MAXBRIGHTNESS / 10 # We want 10-percent increments

# Get current brightness value
current = check_output(
            "pkexec mate-power-backlight-helper --get-brightness",
            shell = True
          )

# Update brightness value
current = float(current)
new = current
if args.direction == "+":
    new += STEP
else:
    new -= STEP

# Prevent (under/over)flow of new value
if new < 0:
    new = 0
if new > MAXBRIGHTNESS:
    new = MAXBRIGHTNESS

# Update brightness
call(
        "pkexec mate-power-backlight-helper --set-brightness " + str(int(new)),
        shell = True
    )
2 Likes

Just want to say that I just had that same issue after installing mate 18.10 and the solution proposed here worked perfectly. Thanks !

It worked for me on ubuntu 18.04.
first install the package below
"mate-power-manager"
and proceed through the steps above.
My max brightness is 24000. So, make sure to change the max brightness value.