#!/usr/bin/python # Run a command when the screensaver activates, ie when the system is idle. # NOTE: only works with gnome-screensaver # License: GNU GPL version 2. # Author: Mike Peters import os import time # The executable you wish to run RUNME = "aMule" # Arguments you wish to pass to the command above ARGS = "" screensaver_started = 0 running = 0 while 1: active = 0 out = "" pid = 0 if screensaver_started == 0: # Don't do anything if the screensaver isn't running s = os.popen("pidof gnome-screensaver") spid = s.read() s.close() if len(spid) > 0: screensaver_started = 1 else: h = os.popen("gnome-screensaver-command -q", "r") out = h.read() active = out.find("inactive") h.close() if active < 0 and running == 0: os.system("%s %s &" % (RUNME, ARGS)) running = 1 elif active > 0 and running == 1: os.system("pkill %s" % RUNME) running = 0 time.sleep(5)