Tuesday, May 8, 2012

Setting brightness at Ubuntu startup



In Ubuthu machines such as Thinkpad T520 every-time when we restart the computer the brightness level will be at its maximum and then we need to manually set the brightness to a comfortable level.

To solve this issue here I share a small script I have written.

First install xdotool
sudo apt-get install xdotool
This will allow you to change the brightness easily from the command line with out admin privileges.


Check whether the brightness is changing with the following command
xdotool key XF86MonBrightnessDown

Now we have to find the file where the brightness value is stored, try doing
cat /sys/class/backlight/acpi_video0/brightness
If you get an integer value then your good to proceed, else you have to find the appropriate file in your system. In that case check in /sys/class/


Adjust the brightness and find your desired brightness level using the above command E.g. 9


In this example I have used 9 as my brightness level change it according to you.

 
#!/bin/bash

myBrightness=9;
currentBrightness=`cat /sys/class/backlight/acpi_video0/brightness`;
count=$(( $currentBrightness - $myBrightness )) ;
while [ $count -gt 0 ]
do
     xdotool key XF86MonBrightnessDown
     let  count=$(($count-1));
done
Save this as brightness.sh


Then make this file to be an executable, by running
chmod +x brightness.sh

Finally open the "Startup Applications" click Add and add the following


Name :<appropriate name>
Command:/<path to file from root>/brightness.sh
Comment:<appropriate comment>

12 comments:

  1. Still my way is easier...!

    http://blog.ishans.info/2011/09/25/set-brightness-automatically-at-the-startup-in-linux/

    ReplyDelete
  2. thank you, finally working solution for Lenovo.

    ReplyDelete
  3. Finally a working (like a charm) and nice solution for my Samsung R580 on nv driver (impossible to control nVidia proprietary driver that way - only via nVidia settings). You could modify the script not only to lower screen brightness, but also to rise it when to dark. Thank you very much:)

    ReplyDelete
  4. Works with Lenovo X121e. Nice! Thank you verry much!

    ReplyDelete
  5. when i press cat /sys/class/backlight/acpi_video0/brightness
    there are cat: /sys/class/backlight/acpi_video0/brightness: No such file or directory

    any suggestion??

    ReplyDelete
  6. A more complete solution:

    #!/bin/bash

    myBrightness=9;
    currentBrightness=`cat /sys/class/backlight/acpi_video0/brightness`;
    count=$(( $currentBrightness - $myBrightness )) ;
    if [ $count -gt 0 ]
    then
    # Too bright
    while [ $count -gt 0 ]
    do
    xdotool key XF86MonBrightnessDown
    let count=$(($count-1));
    done
    else
    # Too dim
    while [ $count -lt 0 ]
    do
    xdotool key XF86MonBrightnessUp
    let count=$(($count+1));
    done
    fi

    ReplyDelete
  7. Looks like brightness values are stored in /sys/class/backlight/intel_backlight/brightness for
    Linux shrimp 3.11.0-17-generic #31-Ubuntu SMP Mon Feb 3 21:52:43 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

    ReplyDelete
  8. #!/bin/bash

    myBrightness=300;
    div=45;
    currentBrightness=`cat /sys/class/backlight/intel_backlight/brightness`;
    count=$(($currentBrightness - $myBrightness )) ;
    count=`expr $count / $div` ;
    if [ $count -gt 0 ]
    then
    # Too bright
    while [ $count -gt 0 ]
    do
    xdotool key XF86MonBrightnessDown
    let count=$(($count-1));
    done
    else
    # Too dim
    while [ $count -lt 0 ]
    do
    xdotool key XF86MonBrightnessUp
    let count=$(($count+1));
    done
    fi

    This works well in Lenovo z500 ubuntu 13.10

    ReplyDelete
  9. Script doesn't work. Only reduces it by one number.

    ReplyDelete
  10. I bookmarked these excellent reminders. Thank you. I believe I follow these tips, but bookmarking as a reference makes this a nice blog. also write a amazing blog for amazon user 10 tips to save money on Amazon just read it and save your money on every deal

    ReplyDelete
  11. Choose high quality and durable dennys driveshaft replacement parts for your Nissan. Replacement parts are available for your air intake system, body electrical, body mechanical and trim, body sheet metal, brakes, climate control, clutch, cooling system, diesel injection, drive belts, drive shafts and axle, engine electrical, engine parts, exhaust, fuel delivery, steering, suspension, tools and hardware, transmission. Replacement parts keep your Nissan running and looking great, these parts will surely make it more stylish, more fun to drive, more comfortable and convenient, and more high-tech. dennys driveshaft .

    ReplyDelete