#!/usr/bin/python import os import subprocess res = subprocess.check_output('xset -q', shell=True).decode('UTF-8') caffeined = "DPMS is Disabled" in res if caffeined: os.system('xset dpms 600 600 600') else: os.system('xset -dpms')