Skip to content

Instantly share code, notes, and snippets.

@Ertain
Last active April 23, 2017 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ertain/7a83b8aecd7e81dd3e1e516ae018032f to your computer and use it in GitHub Desktop.
Save Ertain/7a83b8aecd7e81dd3e1e516ae018032f to your computer and use it in GitHub Desktop.
This is a script for dimming the backlight on my Dell laptop
#!/bin/bash
# Since my backlight is not dimming on its own, I have resorted
# to getting a Bash script to do it for me. This script waits
# a certain amount of seconds (passed as input) until it dims
# the screen.
# This script was found here: http://askubuntu.com/a/762994
# Jason Anderson, February 2, 2017
# This checks to see whether a number has been passed to the
# script. It was found here: http://stackoverflow.com/a/806923
if ! [[ $1 =~ ^[0-9]+$ ]]; then
echo "Please pass an integer." >&2
exit 2
fi
if [ ! $(which xprintidle) ]; then
echo "Please install xprintidle." >&2
exit 1
fi
if [ ! $(which xbacklight) ]; then
echo "Please install xbacklight." >&2
exit 3
fi
if [ -f ~/config_for_dim_screen.conf ]; then
source ~/config_for_dim_screen.conf
else
echo "Configuration file not found." >&2
exit 4
fi
div=1000
limit="$1"
dimmed=false
# dim_percent=6
# time_spent_fading=70
current_brightness=0
while true
do
sleep 0.4
let idle="$(xprintidle)"
if [ $(($idle / $div)) -gt $limit ] && [ $dimmed == false ]; then
current_brightness=$(xbacklight -get)
xbacklight -dec $dim_percent -time $time_spent_fading
dimmed=true
elif [ $(($idle / $div)) -le $limit ] && [ $dimmed == true ]; then
xbacklight -inc $dim_percent -time $time_spent_fading
dimmed=false
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment