Created
October 24, 2013 22:25
-
-
Save owad/7146211 to your computer and use it in GitHub Desktop.
Steps:
1. Make the file executable.
2. Create two keyboard shortcuts - /home/some_user/scripts/this_file.py -up - /home/some_user/scripts/this_file.py -down
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import subprocess | |
from sys import argv | |
MAX = 1.0 | |
MIN = 0.05 | |
STEP = 0.1 | |
def run_process(exe): | |
p = subprocess.Popen(exe, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
while(True): | |
retcode = p.poll() | |
line = p.stdout.readline() | |
yield line | |
if(retcode is not None): | |
break | |
def get_brightness(): | |
for line in run_process(['xrandr', '--verbose']): | |
if 'Brightness' in line: | |
return float(line.split(':')[1].strip()) | |
def set_brightness(brightness): | |
subprocess.Popen(['xrandr', '--output', 'eDP1', '--brightness', '%s' % brightness]) | |
def up(): | |
bright = get_brightness() | |
new_bright = bright + STEP if bright < MAX else bright | |
set_brightness(min(new_bright, MAX)) | |
def down(): | |
bright = get_brightness() | |
new_bright = bright - STEP if bright > MIN else bright | |
set_brightness(max(new_bright, MIN)) | |
if __name__ == "__main__": | |
if len(argv) == 2: | |
func = argv[1] | |
if func == '-up': | |
up() | |
if func == '-down': | |
down() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment