Last active
January 12, 2018 12:14
-
-
Save cGuille/787f7dd9b21f9deac6f5feb663ce3f93 to your computer and use it in GitHub Desktop.
Command line utility to switch between full and low brightness using xbacklight.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [[ $* == *-h* ]]; then | |
cat <<USAGE | |
Switch between full and low brightness using xbacklight. | |
sween [low-brightness] | |
low-brightness defaults to 5, and is a percentage. | |
USAGE | |
exit 1 | |
fi | |
LOW_BRIGHTNESS=${1:-5} | |
FULL_BRIGHTNESS=100 | |
MID_BRIGHTNESS=$(( (100 - $LOW_BRIGHTNESS) / 2 + $LOW_BRIGHTNESS )) | |
CURRENT_BRIGHTNESS="$(xbacklight)" | |
CURRENT_BRIGHTNESS=${CURRENT_BRIGHTNESS%.*} | |
if (( $CURRENT_BRIGHTNESS > $MID_BRIGHTNESS )); then | |
BRIGHTNESS=$LOW_BRIGHTNESS | |
else | |
BRIGHTNESS=$FULL_BRIGHTNESS | |
fi | |
STEPS=$(( $CURRENT_BRIGHTNESS - $BRIGHTNESS )) | |
if (( $STEPS < 0 )); then | |
STEPS=$(( $STEPS * -1 )) | |
fi | |
TIME=$(( $STEPS * 10 )) | |
xbacklight = $BRIGHTNESS -time $TIME -steps $STEPS & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment