Skip to content

Instantly share code, notes, and snippets.

@ldante86
Created November 14, 2016 19:40
Show Gist options
  • Save ldante86/e532ecc4cba6342d05b46268aa7b0360 to your computer and use it in GitHub Desktop.
Save ldante86/e532ecc4cba6342d05b46268aa7b0360 to your computer and use it in GitHub Desktop.
Dim the screen with xbacklight using 1, 2, 3 buttons.
#!/bin/bash -
# Dim the screen with xbacklight using 1, 2, 3 buttons.
dim()
{
local prog=/usr/bin/xbacklight
local step=20 state
which $prog >/dev/null
case $? in
1) echo $prog is not installed
return 1
esac
while true
do
state=$($prog -get)
echo -n "${state%%.*}%% "
read -sn1
case $REPLY in
1|[Ww]) $prog -inc $step ;;
2|[Ss]) $prog -dec $step ;;
3|[Xx]) echo; break ;;
*) continue ;;
esac
state=$($prog -get)
if ((${state%%.*}==100)) || ((${state%%.*}==0)); then
echo ${state%%.*}%%
return 1
fi
done
}
dim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment