forked from BlackMac/timetrack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreenidle.pl
More file actions
51 lines (42 loc) · 1.25 KB
/
Copy pathscreenidle.pl
File metadata and controls
51 lines (42 loc) · 1.25 KB
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
#!/usr/bin/perl
use DateTime;
use POSIX qw(setsid);
$x=`ps -A | grep screenidle.pl`;
$url= "%%URL%%";
$hash= "%%HASH%%";
@lines = split("\n", $x);
$lines =@lines;
if ($lines > 1) {
$dt = DateTime->now();
print "[".$dt->datetime()."] *** already running ***\n";
exit();
}
chdir '/';
umask 0;
open STDIN, '/dev/null';
open STDERR, '>/dev/null';
defined(my $pid = fork);
exit if $pid;
setsid;
$dt = DateTime->now();
print "[".$dt->datetime()."] *** starting ***\n";
#open (LOGFILE, '>>/var/log/screensaver.log');
#print LOGFILE "#[".$dt->datetime()."] *** starting ***\n";
#close (LOGFILE);
system('curl "'.$url.'?h='.$hash.'&d=starting"');
my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver',member='ActiveChanged'\"";
open (IN, "$cmd |");
while (<IN>) {
$dt = DateTime->now();
#open (LOGFILE, '>>/var/log/screensaver.log');
if (m/^\s+boolean true/) {
system('curl "'.$url.'?h='.$hash.'&d=out"');
#print LOGFILE "-[".$dt->datetime()."] *** Locked Screen ***\n";
system("/usr/bin/killall pidgin");
} elsif (m/^\s+boolean false/) {
system('curl "'.$url.'?h='.$hash.'&d=in"');
#print LOGFILE "+[".$dt->datetime()."] *** Unlocked Screen ***\n";
system("/usr/bin/nohup /usr/local/bin/pidgin &");
}
#close (LOGFILE);
}