qbb :: Bash script for setting screen backlight brightness from command line

A quick useful shell script for setting screen backlight brightness from command line. Updates on my github: https://github.com/xdth/qbb/blob/master/qbb

#!/bin/bash
# ##########################################################################################
# #### Description
#
# Adjusts screen backlight brightness from command line. It takes as argument a percentage
# and calculates the final value, based on the maximum brightness of the monitor.
#
# Usage:
# qbb [percentage]
#
# Example for setting brightness to 50%:
# qbb 50
#
# Author: dth@dthlabs.com
# Date: July 9, 2019.
#
# ##########################################################################################
# #### Settings

# Full path of the 'max_brightness' file, containing the maximum brightness of the monitor
max_brightness_path="/sys/class/backlight/intel_backlight/max_brightness"

# Full path of the 'brightness' file, containing the current brightness of the monitor
current_brightness="/sys/class/backlight/intel_backlight/brightness"

# ##########################################################################################
# #### Main

# Get the argument
desired_brightness=$1

# Get the maximum brightness and put into a variable
max_brightness=$(cat "$max_brightness_path")     

# Calculate the final value
final_value=$(($max_brightness * $desired_brightness / 100))

# Set the final value
echo $final_value > $current_brightness

# Return message
echo 'Setting the backlog value to' $final_value '('$desired_brightness'%' of $max_brightness')'

Leave a Reply

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

Loading Facebook Comments ...
Loading Disqus Comments ...