Skip to content

Instantly share code, notes, and snippets.

@SergKolo
Created July 9, 2016 21:28
Show Gist options
  • Save SergKolo/a7d19377ab530d2a7a0027866d7e4488 to your computer and use it in GitHub Desktop.
Save SergKolo/a7d19377ab530d2a7a0027866d7e4488 to your computer and use it in GitHub Desktop.
#!/bin/bash
# We want to find the directory where all the backlight data
# is stored , based on the fact that there's always "actual_brightness"
# file in that directory
DIR=$(find /sys/devices/ -type f -name "actual_brightness" -printf "%h" )
# Graphic cards all have different integer value for
# maximum level of brightness, so we need to get it
MAX=$(cat "$DIR"/max_brightness )
# Percentage which we want to set
PERCENT="0.4"
# Calculate new value
NEW=$( bc <<< "$MAX*$PERCENT" )
# Print out the resulting float number
# as int to the controlling file
printf "%.0f" "$NEW" > "$DIR"/brightness
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment