Skip to content

Instantly share code, notes, and snippets.

@SergKolo
Last active May 3, 2019 21:46
Show Gist options
  • Save SergKolo/cdb137664b68abae8663082366678af6 to your computer and use it in GitHub Desktop.
Save SergKolo/cdb137664b68abae8663082366678af6 to your computer and use it in GitHub Desktop.
#!/bin/bash
#set -x
wait_ac_connect()
{
while ! on_ac_power ; do : ; sleep 0.25 ; done && echo PLUGGED_IN
}
wait_ac_disconnect()
{
while on_ac_power ; do : ; sleep 0.25 ; done && echo UNPLUGGED
}
change_brightness()
{
# dbus-send --session --print-reply\
# --dest=org.gnome.SettingsDaemon.Power\
# /org/gnome/SettingsDaemon/Power \
# org.gnome.SettingsDaemon.Power.Screen.SetPercentage uint32:"$1"
qdbus org.gnome.SettingsDaemon /org/gnome/SettingsDaemon/Power org.gnome.SettingsDaemon.Power.Screen.SetPercentage "$1"
}
get_brightness()
{
qdbus org.gnome.SettingsDaemon \
/org/gnome/SettingsDaemon/Power \
org.gnome.SettingsDaemon.Power.Screen.GetPercentage
}
BAT_PERCENTAGE=50
AC_PERCENTAGE=90
while true
do
if on_ac_power ; then
wait_ac_disconnect
AC_PERCENTAGE=$(($(get_brightness)+1))
sleep 0.25
change_brightness "$BAT_PERCENTAGE"
else
wait_ac_connect
BAT_PERCENTAGE=$(($(get_brightness)+1))
sleep 0.25
change_brightness "$AC_PERCENTAGE"
fi
sleep 0.25
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment