How to change the brightness via CLI?

Hey there!

I want to control my Laptop via KDE connect. So a command to increase the brightness by 1, and to decrease it by 1 is needed :slight_smile:

It should not depend on the connected display

Fedora 41
Plasma 6.3.x
Wayland

  • Increase
qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl org.kde.Solid.PowerManagement.Actions.BrightnessControl.setBrightness $(($(qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl org.kde.Solid.PowerManagement.Actions.BrightnessControl.brightness) + 10))
  • Decrease
qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl org.kde.Solid.PowerManagement.Actions.BrightnessControl.setBrightness $(($(qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl org.kde.Solid.PowerManagement.Actions.BrightnessControl.brightness) - 10))
2 Likes

thanks I would like to use this. I converted it into a script for Fedora.

Interestingly, the steps are in 1/100 %, so 100 means 1%.

long script
#!/bin/bash

# Check if the user provided an argument
if [ -z "$1" ]; then
    echo "Usage: brightness <value>"
    exit 1
fi

# Check if the argument is a valid integer
if ! [[ $1 =~ ^-?[0-9]+$ ]]; then
    echo "Error: Argument must be an integer"
    exit 1
fi

# Get current brightness level
current_brightness=$(qdbus-qt6 org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl org.kde.Solid.PowerManagement.Actions.BrightnessControl.brightness)

echo "current: $(($current_brightness / 100))"

# Calculate step size
step=$(($1 * 100))

# Calculate new brightness level
new_brightness=$((current_brightness + $step))

# Set the new brightness level
qdbus-qt6 org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl org.kde.Solid.PowerManagement.Actions.BrightnessControl.setBrightness "$new_brightness"

echo "new: $(($(qdbus-qt6 org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl org.kde.Solid.PowerManagement.Actions.BrightnessControl.brightness) / 100))"

This is the short form:

#!/bin/bash
qdbus-qt6 org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl org.kde.Solid.PowerManagement.Actions.BrightnessControl.setBrightness "$(($(qdbus-qt6 org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl org.kde.Solid.PowerManagement.Actions.BrightnessControl.brightness) + $(($1 * 100))))"

1 Like

Great, nothing like marking your own comment as a solution :wink:

I am so confused what you want to tell me with this comment lol

You got your solution:

Then you quoted that and marked your post as the solution.

It’s like copying text from a book, then saying you wrote it.

No. Your command used a different name not used on Fedora.

And the step size was not correct.

I used that groundwork and improved it a bit. So that seems fair, as the command didnt yet work

1 Like

Ah, ok - no problem.