Skip to content

Instantly share code, notes, and snippets.

@atilberk
Last active May 23, 2023 18:58
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 atilberk/38c13eda1f0d4874ca2dd453ee1c2a68 to your computer and use it in GitHub Desktop.
Save atilberk/38c13eda1f0d4874ca2dd453ee1c2a68 to your computer and use it in GitHub Desktop.
A simple shell script for Ubuntu to adjust screen brightness
#!/bin/sh
# Usage:
# sh /path/to/adjust_brightness.sh [up|down|<an integer between 0-100>]
# Requires the change of ownership of the baclight file to the user
# Run this once to change the ownership:
# "sudo chown $(whoami):$(whoami) /sys/class/backlight/intel_backlight/brightness"
# You can then assign keyboard shortcuts to adjust brightness. For example,
# "sh /path/to/adjust_brightness.sh up" -> "CTRL + B"
# "sh /path/to/adjust_brightness.sh down" -> "CTRL + N"
command=$1
brightness="/sys/class/backlight/intel_backlight/brightness"
max_brightness="/sys/class/backlight/intel_backlight/max_brightness"
if [ "$command" = "up" ]; then
echo $(( $(cat $backlight) + $(cat $max_brightness) / 10 )) | tee $backlight
elif [ "$command" = "down" ]; then
echo $(( $(cat $backlight) - $(cat $max_brightness) / 10 )) | tee $backlight
else
echo $(( $1 * $(cat $max_brightness) / 100)) | tee $backlight
fi
@underwoerld
Copy link

best script ever, i have been using it for years now :) many thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment