I tried using xbacklight, but it wasnt working so I made some custom global commands to control the brightness. For example:
"Bright" :
sudo bash -c "echo 20 > /sys/class/backlight/acpi_video0/brightness"
"Mid" :
sudo bash -c "echo 10 > /sys/class/backlight/acpi_video0/brightness"
"Dark" :
sudo bash -c "echo 0 > /sys/class/backlight/acpi_video0/brightness"
I want to make two more commands, one that will increase the brightness by one and one that will decrease the brightness by one.
Is there some code I can use in place of 'echo "NUMBER"' that will decrease / increase the current value by one.
I know that the current brightness level is the document: /sys/class/backlight/acpi_video0/brightness which currently reads "20" and changes when using the brightness commands.
I have no idea what this command would be like but something like
sudo bash -c "echo [ONE LESS THAN] /sys/class/backlight/acpi_video0/brightness > /sys/class/backlight/acpi_video0/brightness"
I dont know if this is possible, but thanks for any help.
Update
What is the correct usage?
When I run "sudo ./brightness.sh +1" it outputs :
Usage:
sudo brightness.sh [ + | - | INTEGER ]
./brightness.sh: 10: [: +: unexpected operator
./brightness.sh: 23: [: +: unexpected operator
./brightness.sh: 38: ./brightness.sh: [[: not found
<<< ERROR: wrong parameter
./brightness.sh: 44: ./brightness.sh: printUsage: not found
and when I run "sudo bash brightness.sh +1" it outputs :
Usage:
sudo brightness.sh [ + | - | INTEGER ]
brightness.sh: line 27: [: -1: unary operator expected
brightness.sh: line 34: : No such file or directory
Best Answer
Why not make one command that will increase by one or decrease by one based on the options you pass to it ? That's the basic idea behind the script you will see bellow. We store current value in
CURRENT
variable, then usebash
's arithmetic expansion$(( numberA + numberB ))
to increase or decrease by one. As for decision making, we call the script with single command line argument+
to increase , or-
for decrease.Per muru's suggestion in the comments , I also made a small edit to the code, which now allows you to call
brightness.sh
with an integer parameter less than or equals to the max brightness