7

I'm using Ubuntu Trusty tahr and I've noticed that there is no brightness control (like a slider), In windows I'll use Intel's graphics media accelerator to reduce brightness but here it looks impossible.

I'll be using my computer late hours to study and My monitor's hardware buttons are busted out so any help would be apreciated.

3

On this site, a while ago I found an nice script from someone. THIS IS NOT MINE!

enter image description here

I am using it ever since on my netbook, running Xubuntu and it seems to run on anything.

For reasons of not posting a link-only answer, here it is:

#!/usr/bin/env python

from gi.repository import Gtk
import subprocess

class BrightnessScale:
    def __init__(self):
        # get active monitor and current brightness
        self.monitor = self.getActiveMonitor()
        self.currB = self.getCurrentBrightness()

    def initUI(self):
        # initliaze and configure window 
        window = Gtk.Window()
        window.set_title('Brightness Scale')
        window.set_default_size(250, 50)
        window.set_position(Gtk.WindowPosition.CENTER)
        window.set_border_width(10)

        # slider configuration
        self.adjustment = Gtk.Adjustment(self.currB, 0, 100, 1, 10, 0)
        self.scale = Gtk.HScale()
        self.scale.set_adjustment(self.adjustment)
        self.scale.set_digits(0)

        # close Gtk thread on closing window
        window.connect("destroy", lambda w: Gtk.main_quit())

        # setup event handler on value-changed
        self.scale.connect("value-changed", self.scale_moved)

        # add the scale to window
        window.add(self.scale)

        # show all components in window
        window.show_all()

        # close window on pressing escape key
        accGroup = Gtk.AccelGroup()
        key, modifier = Gtk.accelerator_parse('Escape')
        accGroup.connect(key, modifier, Gtk.AccelFlags.VISIBLE, Gtk.main_quit)
        window.add_accel_group(accGroup)

    def showErrDialog(self):
        self.errDialog = Gtk.MessageDialog(None, 
                                           Gtk.DialogFlags.MODAL,
                                           Gtk.MessageType.ERROR,
                                           Gtk.ButtonsType.OK,
                                           "Unable to detect active monitor, run 'xrandr --verbose' on command-line for more info")
        self.errDialog.set_title("brightness control error")
        self.errDialog.run()
        self.errDialog.destroy()

    def initStatus(self):
        if(self.monitor == "" or self.currB == ""):
            return False
        return True

    def getActiveMonitor(self):
        #Find display monitor
        monitor = subprocess.check_output("xrandr -q | grep ' connected' | cut -d ' ' -f1", shell=True)
        if(monitor != ""):
            monitor = monitor.split('\n')[0]
        return monitor

    def getCurrentBrightness(self):
        #Find current brightness
        currB = subprocess.check_output("xrandr --verbose | grep -i brightness | cut -f2 -d ' '", shell=True)
        if(currB != ""):
            currB = currB.split('\n')[0]
            currB = int(float(currB) * 100)
        else:
            currB = ""
        return currB

    def scale_moved(self, event):
        #Change brightness
        newBrightness = float(self.scale.get_value())/100
        cmd = "xrandr --output %s --brightness %.2f" % (self.monitor, newBrightness)
        cmdStatus = subprocess.check_output(cmd, shell=True)

if __name__ == "__main__":
    # new instance of BrightnessScale
    brcontrol = BrightnessScale()
    if(brcontrol.initStatus()):
        # if everything ok, invoke UI and start Gtk thread loop
        brcontrol.initUI()
        Gtk.main()
    else:
        # show error dialog
        brcontrol.showErrDialog()

How to use

  • Paste the script into an empty file, save it as brightness_set in ~/bin (you probably have to create the directory). Make it executable

  • Add it to a shortcut key: Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:

    brightness_set
    
  • Log out and back in and it should work


Edit

To make a nice set, you could make the slider available in Dash, the Launcher or any other application menu, by adding a .desktop file in ~/.local/share/applications

enter image description here

[Desktop Entry]
Type=Application
Name=Brightness Scale
Icon=/path/to/set_brightness.png
Exec=brightness_set
OnlyShowIn=Unity;
  • In the Icon= line, set the path to the icon. Yopu can choose your own icon, or save the icon below as set_brightness.png:

    enter image description here

  • In the Exec= line, the assumption is that the script is in $PATH (which includes ~/bin on Ubuntu), and executable
  • This works, but only for the primary monitor. – That Brazilian Guy Mar 10 '16 at 12:43
3

This does not make your brightness function keys work, but is a workround.

Install Brightness Controller with the following commands: Install Brightness Controller with the following commands:

sudo add-apt-repository ppa:apandada1/brightness-controller
sudo apt-get update

For Version 1 with up to 4 Monitor Support:

sudo apt-get install brightness-controller

sudo apt-get install brightness-controller-simple

]([![Brightness Controller Version 1

For Version 2 with Multi Monitor Support and other features: You can control brightness of two monitors using its sliders.

sudo apt-get install brightness-controller


(source: ubuntu.com)

enter image description here

  • According to the developer, this solution works only for up to 2 displays. – That Brazilian Guy Mar 11 '16 at 17:44
1

A script to make setting the brightness more easier, based on xrandr and zenity:

#! /bin/bash

displays=($(xrandr | awk '/ connected /{print $1}'))

if (( ${#displays[@]} > 1 ))
then
    selected_display="$(zenity --list --title 'Select Display' --radiolist --column '' --column 'Display' $(xrandr | awk '/ connected /{print NR,$1}'))"
else
    selected_display="${displays[0]}"
fi

zenity --scale --title "Set brightness of $selected_display" --value=100 --print-partial |
while read brightness
do
    xrandr --output "$selected_display" --brightness $(awk '{print $1/100}' <<<"$brightness"})
done

Install Zenity and xrandr:

sudo apt-get install x11-xserver-utils zenity

Save the script somewhere, make it executable (chmod +x some-script.sh), make a launcher if you wish. Then you can run the script and use this GUI to set the brightness.

Screenshots:

display selection brightness slider

1

Custom brightness controls script using dbus and zenity scale

enter image description here

Introduction:

Knowing that Ubuntu's Unity relies on dbus service to communicate many settings and events to kernel and hardware, I've put together a simple bash script that relies on dbus and zenity --scale.

Installation

The script can be copied from here, or imported from my github.

To manually copy the script:

  1. Open gedit text editor, copy over the code, save the file. Remember the location. Preferably it would be in $HOME/bin folder.
  2. Open terminal, navigate to the script location. Issue chmod +x scriptName.sh
  3. At this point script is ready to work. You can bind it to keyboard shortcut, or desktop, or launcher.

To import from github:

  1. sudo apt-get install git
  2. If you don't have $HOME/bin directory, create one.
  3. cd $HOME/bin/; git clone https://github.com/SergKolo/sergrep.git

Once download completes, ubright.sh is ready to be used, located in $HOME/bin/sergrep.

Script Source

#!/usr/bin/env bash
#
###########################################################
# Author: Serg Kolo , contact: 1047481448@qq.com 
# Date: February 25th, 2016
# Purpose: Simple brightness control for Ubuntu Unity
# Written for: https://askubuntu.com/q/583863/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.


# set -x
ARGV0="$0"
ARGC="$#"

main ()
{
  local DISPLAY=:0 
 getPercentage | setBrightness > /dev/null
 # echo $(getPercentage)
}

setBrightness()
{
  local PERCENTAGE
  read PERCENTAGE
  [[ -n "$PERCENTAGE"   ]] || exit 1
  dbus-send --session --print-reply\
    --dest=org.gnome.SettingsDaemon.Power\
    /org/gnome/SettingsDaemon/Power \
    org.gnome.SettingsDaemon.Power.Screen.SetPercentage uint32:"$PERCENTAGE"
}

getPercentage()
{
  local PCT
  PCT="$(zenity --scale --text='Choose brightness level')" 
  if [[ -n PCT ]]
  then
      echo "${PCT}"
  fi
}

main

Additional Info: While many answers here rely on xrandr, it's worth to note that xrandr is not an "actual" hardware solution, i.e., it may change colouring of the screen such that it appears less bright, but the actual power consumption from the screen does not decrease. From xrandr man page:

--brightness brightness

Multiply the gamma values on the crtc currently attached to the output to specified floating value. Useful for overly bright or overly dim outputs. However, this is a software only modification, if your hardware has support to actually change the brightness, you will probably prefer to use xbacklight.

This answer relies on the dbus interface, which alters the actual brightness setting, represented by a file in /sys/class/backlight's sub-folder. Thus , through using dbus we actually control the hardware.

Related posts

  • I see ARGV0="$0" and ARGC="$#" defined but not referenced. Am I missing something? – WinEunuuchs2Unix Feb 14 '18 at 12:04
1

Eyesome

I developed Eyesome that runs 24/7 to:

  • Control display brightness and gamma (night light, etc) for three monitors.
  • Each morning it gets the sunrise and sunset times from the internet based on your city name.
  • Brightness and gamma is gradually increased after sunrise
  • Brightness and gamma is gradually decreased before sunset
  • Sleeps ~ 12 hours daily and nightly unless resuming from suspend or monitors switched on/off

Sample Configuration - General Tab

enter image description here

Sample Configuration - Monitor 3 Tab

eyesome configuration monitor 3.png

0

You also have a brigthness control tray applet here :

https://launchpad.net/indicator-brightness

In case that can help. (it works great for me.)

  • I've tried this one but it says No backlit device found – Karthikeyan R Feb 13 '15 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.