I recently migrated to 64 Bit 16.04 LTS from 32 Bit 14.04 LTS on my Toshiba L645 laptop. In 14.04 LTS system, I had a script that automatically updated the brightness level depending on the power source. Unfortunately I didn't save that script before overwriting the system. Currently, I am using the following script
#!/usr/bin/env bash
#
###########################################################
# Author: Serg Kolo , contact: 1047481448@qq.com
# Date: February 26 2016
# Purpose: Brightness control that polls for
# ac adapter presence. Uses
# Dependencies: on_ac_power script, dbus, Unity/Gnome
# Written for: http://askubuntu.com/q/739617/295286
# Tested on: Ubuntu 14.04 LTS
###########################################################
# Copyright: Serg Kolo , 2016
#
# Permission to use, copy, modify, and distribute this software is hereby granted
# without fee, provided that the copyright notice above and this permission statement
# appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
# uncomment the line bellow for debugging
#set -x
ARGV0="$0"
ARGC=$#
main()
{
# defaults
local DISPLAY=:0
local DECREASE=30
local INCREASE=75
local RCFILE="$HOME/.auto-backlightrc"
#---
# Check the settings
if [ -f $RCFILE ]
then
source $RCFILE
else
create_rcfile $DECREASE $INCREASE
fi
#---
# now actually test if we're using ac adapter
if ! on_ac_power
then
change_brightness $DECREASE
# The two lines bellow are optional for
# setting brightness if on AC. remove #
# if you want to use these two
# else
# change_brightness $INCREASE
fi
}
change_brightness()
{
dbus-send --session --print-reply\
--dest=org.gnome.SettingsDaemon.Power\
/org/gnome/SettingsDaemon/Power \
org.gnome.SettingsDaemon.Power.Screen.SetPercentage uint32:"$1"
}
create_rcfile()
{
echo "DECREASE="$1 > "$RCFILE"
echo "INCREASE="$2 >> "$RCFILE"
}
while true
do
main
sleep 0.25
done
However, this script only works when power is switched from AC to Battery and does not restore the brightness level once the AC is back on. Also, once on Battery, this script consistently tries to set the brightness at the predefined level and even if I try to change that manually it resets that. I would like to be able to change the brightness level manually if I desire even in battery mode.
UNPLUGGED 50 PLUGGED_IN Error: org.gtk.GDBus.UnmappedGError.Quark._gsd_2drr_2derror_2dquark.Code3 out of brightness range: 4694, has to be 4648 -> 1
– thethakuri Jun 18 '16 at 07:34max_brightness
file, the maximum level of brightness is4648
. But the good news is the script is responding to the events nevertheless ! – thethakuri Jun 18 '16 at 07:37PLUGGED_IN
the brightness value is set at 4694 which is greater than max value of 4648. How was that number calculated ? Also, no matter what value I set forAC_PERCENTAGE
it gives back the same number: 4694 – thethakuri Jun 18 '16 at 07:44DISPLAY=:0
in the script. You're the trooper. Thanks a lot. Man I gotta learn shell scripting. It would be great if you could decrease the brightness level depending on the battery level as well. – thethakuri Jun 18 '16 at 08:16