Seems determining if the screensaver is active is a pretty good indicator of whether a user is currently using the system. Bundle that with evaluation of the system load and you can get a pretty good indication of an idle system.
Following is a Tcl-script that determines if the system screen saver is active. One could imaging bundling this will suspending/resuming a process or virtual machine to make use of the idle time.
Let me know what you think and usages you may think of.
#!/usr/bin/tclsh
proc isScreenSaverRunning { } {
set response [exec gnome-screensaver-command -q]
# puts $response
foreach e [split $response \n] {
switch -glob -- $e {
"* inactive"
{
set running 0
}
"* active"
{
set running 1
}
default
{
}
}
}
return $running
}
proc check { } {
set running [isScreenSaverRunning]
if { $running } {
puts "screen saver running"
exit
}
after 1000 [list check]
}
#-----main------
after 1000 [list check]
vwait forever
No comments:
Post a Comment