dell - Brightness Profiles Ubuntu 14.04.5 - Ask Ubuntu
usually, laptop screens dim set lowest level of brightness when charger not present, , brighten max level if charger present/connected. however, on dell inspiron 7559 skylake laptop, not happen. laptop on 100% brightness. how can retrieve "feature"?
introduction
the script below modified version of previous scripts, written in python , using dbus exclusively polling ac_adapter presence , setting screen brightness.
usage
usage simple: call command line
python ./brightness_control.py
the script defaults 100% brightness on ac , 10% on battery. users can use -a
, -b
set desired brightness levels on ac , battery respectively.
as given -h
option:
$ ./brightness_control.py -h usage: brightness_control.py [-h] [-a adapter] [-b battery] simple brightness control laptops, depending on presense of ac power supply optional arguments: -h, --help show message , exit -a adapter, --adapter adapter brightness on ac -b battery, --battery battery brightness on battery
for example, 1 can of following:
# set non default brightness on ac $ ./brightness_control.py -a 80 # set non-default value brightness on battery $ ./brightness_control.py -b 20 # set non-default values both $ ./brightness_control.py -a 80 -b 20
source
also available on github
#!/usr/bin/env python """ author: serg kolo <1047481448@qq.com> date: nov 3rd , 2016 purpose:brightness control depending on presence of ac adapter written for: http://askubuntu.com/q/844193/295286 """ import argparse import dbus import time import sys def get_dbus_property(bus_type, obj, path, iface, prop): """ utility:reads properties defined on specific dbus interface""" if bus_type == "session": bus = dbus.sessionbus() if bus_type == "system": bus = dbus.systembus() proxy = bus.get_object(obj, path) aux = 'org.freedesktop.dbus.properties' props_iface = dbus.interface(proxy, aux) props = props_iface.get(iface, prop) return props def get_dbus_method(bus_type, obj, path, interface, method, arg): """ utility: executes dbus method on specific interface""" if bus_type == "session": bus = dbus.sessionbus() if bus_type == "system": bus = dbus.systembus() proxy = bus.get_object(obj, path) method = proxy.get_dbus_method(method, interface) if arg: return method(arg) else: return method() def on_ac_power(): adapter = get_adapter_path() call = ['system','org.freedesktop.upower',adapter, 'org.freedesktop.upower.device','online' ] if get_dbus_property(*call): return true def get_adapter_path(): """ finds dbus path of ac adapter device """ call = ['system', 'org.freedesktop.upower', '/org/freedesktop/upower','org.freedesktop.upower', 'enumeratedevices',none ] devices = get_dbus_method(*call) dev in devices: call = ['system','org.freedesktop.upower',dev, 'org.freedesktop.upower.device','type' ] if get_dbus_property(*call) == 1: return dev def set_brightness(*args): call = ['session','org.gnome.settingsdaemon.power', '/org/gnome/settingsdaemon/power', 'org.gnome.settingsdaemon.power.screen', 'setpercentage', args[-1] ] get_dbus_method(*call) def parse_args(): info = """ simple brightness control laptops, depending on presense of ac power supply """ arg_parser = argparse.argumentparser( description=info, formatter_class=argparse.rawtexthelpformatter) arg_parser.add_argument( '-a','--adapter',action='store', type=int, help='brightness on ac', default=100, required=false) arg_parser.add_argument( '-b','--battery',action='store', type=int, help='brightness on battery', default=10, required=false) return arg_parser.parse_args() def main(): args = parse_args() while true: if on_ac_power(): set_brightness(args.adapter) while on_ac_power(): time.sleep(1) else: set_brightness(args.battery) while not on_ac_power(): time.sleep(1) if __name__ == "__main__": main()
Comments
Post a Comment