#!/usr/bin/env python3 import sys, os # config: # put your device here device="/sys/class/backlight/amdgpu_bl0/" def smart_int(num): if (num[0] == '+'): return int(num[1:]) return int(num) def do_action(action): if (action == 'show'): curr = get_current() _max = get_max() print('screen brightness is at %s (%d/%d)' % (str(int(curr / _max * 100)), curr, _max)); return if (action[-1:] == '%'): if (action[0] == "+" or action[0] == '-'): curr = get_current() max = get_max() curr_pc = curr / max * 100 put_brightness(int(max * ((curr_pc + smart_int(action[:-1])) / 100))) else: put_brightness(int(get_max() * (int(action[:-1]) / 100))) elif (action[0] == '+' or action[0] == "-"): put_brightness(get_current() + smart_int(action)) elif (action.isdigit()): put_brightness(int(action)) def get_current(): with open(device + 'brightness', 'r') as f: return int(f.read().replace('\n', '')) def put_brightness(ammount): ammount = num_in_range(ammount) print("screen brightnes is " + str(ammount)); with open(device + 'brightness', 'r+') as f: f.write(str(ammount)) def get_max(): with open(device + 'max_brightness', 'r') as f: return int(f.read().replace('\n', '')) def num_in_range(num): max = get_max() if (num > max): num = max if (num < 0): num = 0 return num for action in sys.argv[1::]: do_action(action)