-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidletasks.py
executable file
·52 lines (40 loc) · 1.23 KB
/
idletasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python
# This script is more of an experiment than anything, but it does function.
# To use this:
# 1. Put scripts to run when the system becomes idle in ~/.idletasks/idle.d
# Put scripts to run when the system becomes unidle in ~/.idletasks/unidle.d
# 2. Configure your desktop environment to run this script when you log in.
import dbus
from dbus.mainloop.glib import DBusGMainLoop
from gobject import MainLoop
import os
from os import popen
import glob
def idle_d_tasks():
idle_path = os.path.expanduser('~/.idletasks/idle.d/')
for task in glob.glob(idle_path + '*'):
print "run",
print task
popen(task)
def unidle_d_tasks():
unidle_path = os.path.expanduser('~/.idletasks/unidle.d/')
for task in glob.glob(unidle_path + '*'):
print "run",
print task
popen(task)
def start_tasks():
idle_d_tasks()
def stop_tasks():
unidle_d_tasks()
def idlechange_handler(sender=None):
if sender:
print "just went idle, starting tasks"
start_tasks()
else:
print "just went unidle, stopping tasks"
stop_tasks()
dbus_loop = DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus(mainloop=dbus_loop)
bus.add_signal_receiver(idlechange_handler, "ActiveChanged", "org.gnome.ScreenSaver")
mainloop = MainLoop()
mainloop.run()