Set brightness automatically at the startup in Linux

When ever I restart (or logout and login) my laptop the LCD display brightness is set to the maximum value. Even if I set the brightness settings in the power to the value I need, they won’t be in effect when I restart the machine.

 Please note that rest of the blog article was edited on 5th of August 2012.

To solve this problem I wrote the following python script. First you need to add it to the startup applications list. The command to be given in the startup applications is β€œpython /<path>/<to>/<script>/setBrightness.py < Brightness level>”.

(If you don’t know how to add this to start-up applications please refer http://linuxandfriends.com/2011/06/01/how-to-add-startup-programs-in-gnome-3/ )

An example would be python /home/ishan/.setBrightness/setBrightness.py 20 . If you do not specify a brightness level, the script will change the brightness level according to the time of the day. If it’s between 7am and 8pm, the script will make the brightness be set to 75.  If it’s between 8pm and 7am, the script will make the brightness be set to 20. You can edit these brightness levels by changing the variables day_level and night_level respectively.  

A special thank should go to Sergio Aguilar for adding this neat functionality of brightness changing according to the time of the day and changing the brightness using parameter passing.

If you are using Gnome 3 or Unity – 

Checkout the master branch from https://github.com/ishanthilina/setBrightness.

If you are using Gnome 2 –

Checkout the Gnome2 branch from https://github.com/ishanthilina/setBrightness.

 

Share Button

34 thoughts on “Set brightness automatically at the startup in Linux

  1. please explain how to set the brightness value to all the way bright. I added your script to startup programs but don’t see where to change value from 0 thank you this started with upgrade to ubuntu 11.10 and now my startup is so dark I can hardly see to get to the setting to raise it.

  2. I just tried it and it adjusted the screen brightness but when I restarted the computer it went back to the way it was. Is there something else i need to do after I start up the script?

  3. Pingback: Mengatasi Bug Ubuntu 11.10 : Save Setting Brightness | Eko Suhartono

  4. You should use a setting that is not 0 in your example – 0 sets it to the most dim setting. Other than that – great little script! Thanks, I had this issue on my new Folio 13.

    • Yes, 0 is the most dim and 100 is the brightest. I set the brightness to 0 cz that’s my personal preference. But I have clearly stated in the blog post and comments

      “By default, the script will set the brightness to the minimum value. But if you want to change this, you can do that by editing the value 0 of the β€œvalue” variable to any value between 0 to 100.”

      So it’s up to you to decide the value you need πŸ™‚

  5. What about unity.. my OS is Ubuntu 11.10.
    And this OS has the brightness setting in system setting’s options, but there are some shortcut keys(Fn+F5/F6) can set brightness, too.
    when I reboot it, the value of setting info shows about half of the brightness, but the display didn’t follow. still maximum brightness. but the shortcut keys can reduce it.

    • The script works fine on my Lenovo Edge 15. Thank you from Germany !

      Is there any posibility to enhance the script to the Bluetooth device ? On my 3 Lenovos the built in Bluetooth device is always on, at the startup. Similar to the full brightness.
      I’d like to have Bluetooth disabled as default.

  6. this works great on Mint 12 on my Lenovo Thinkpad x220t.
    thanks a lot !!! πŸ™‚
    if you have more of this cool terminal and scripting stuff, feel free, to “newsletter” me πŸ™‚
    thx !!

  7. On line 44, the indentation of the second else statement prevented the script from working. I un-indented it and the script worked seemlessly.

    Thanks!

    • Hi,

      First of all, I’m really sorry for keeping this comment under moderation for so long time. I totally forgot to approve the comment, only after I saw the comment by Maciek below I noticed that I haven’t approved this comment. Really sorry for that.

      Anyways, can you point out what didn’t work out? Did you try manually running the script?

      Also, if you take a look at the autoinstaller branch in the git repo you’ll find an easy to use version of the same script. It was there from a long time back, but I didn’t have the time to document about it.

      Sorry for being so careless :D. Will document it asap :D.

  8. Brightness on startUp for the HP Folio 13 with Ubuntu 12.04

    -Install xdotool: sudo apt-get install xdotool
    – create a “myfile.sh” with the content:

    #!/bin/bash
    myBrightness=2442;
    currentBrightness=`cat /sys/class/backlight/intel_backlight/actual_brightness`;
    count=$(( $currentBrightness – $myBrightness )) ;
    while [ $count -gt 0 ]
    do
    xdotool key XF86MonBrightnessDown
    let currentBrightness=`cat /sys/class/backlight/intel_backlight/actual_brightness`;
    let count=$(( $currentBrightness – $myBrightness )) ;
    done

    – give it permisions: chmod 777 myfile.sh
    – make it execute on the startup (startup applications>add)
    – Note: use your own myBrightness value for custom brightness.

  9. i am trying to change the brightness in ubuntu 11.10. please give the step by step procedure to change the brightness.and how to write a scripts in python.

  10. Oh man, Thanks for the script
    it worked like a charm in Ubuntu 12.10
    I think there’s an easier way to add this script to start-up applications :
    open the Startup Applications Preferences and then click Add then locate the script and finally click add . i’ve done it and it works

  11. Great! I was googling for a solution for days and found this. It works perfectly on Ubuntu 13.04 beta/HP ProBook 4540s.

    Thanks a lot.

    Kapila

  12. Pingback: How to make Unity remember brightness settings? | Some Ubuntu Questions and Answers

  13. Pingback: Unix:How do I set default brightness after boot? – Unix Questions

Leave a Reply to Eric Cancel reply

Your email address will not be published. Required fields are marked *