Friday, August 29, 2014

Another Useful Script - Better Brightness

Hello All! I know it hasnt been all that long since I last posted but I have another addition to my useful Linux scripts, randoScripts. Here is the previous post regarding this repo: linky! This script is particularly useful on Debian based laptops. If you have one in your possession I am sure that you have noticed that a fresh boot of the system blasts the screen brightness to the max. This script makes it so the brightness is set to a lower value on boot using the rc.local  script.

rc.local Is a script that by default does nothing and is executed last of all the startup scripts. Our plan is to edit this script to lower the screen brightness.

LETS START!

Step 1

All of my scripts are on Github:
$git clone https://github.com/kd8bny/randoScripts.git

The first thing to do is figure out what brightness value works for you. So in order to accomplish this set your display using your function keys or under Brightness & Lock in your settings menu.

Once you have found the desired setting run this command:
$cat /sys/class/backlight/acpi_video0/brightness

IMPORTANT:

If you finish this tutorial and it didnt work for you, you may need to use

/sys/class/backlight/intel_backlight/brightness

instead. For me both worked just fine, however different values were used.

Anyway, the cat command should spit out a number. The number varies depending on your display. Mine happened to be 34 so I will use that in my examples.

If you would like to practice with values via terminal before settling use this:
$echo VALUE | tee /sys/class/backlight/acpi_video0/brightness
Where VALUE is the number you want to use.

Step 2 

 Go ahead and open up the rc.local file and place the value you want in the location of VALUE_HERE. The script should now look like this:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

sleep 1
echo 34 > /sys/class/backlight/acpi_video0/brightness

exit 0

The sleep is somewhat important in this case by waiting until the OS is completely loaded before changing the values.

Step 3

Next move the script into the proper location if you didn’t edit your own.
$sudo mv rc.local /etc
And to enable it we have to make it executable
$sudo chmod +x /etc/rc.local

Fini!

After a reboot you should now see that your screen will start at your desired value. I am considering editing the script to remember the last screen value. Not sure if its worth it.

Question??

I would really like to keep this repo going with many useful scripts. They show the real power of the Linux OS and your control over it.

Would an automated installer be a nice feature to have? Giving the user choices of scripts they may like to have.
Let me know in the comments.


**The customary for those who care
   Ubuntu 14.04, rc.local