The problem#
I want my computer to act differently when I'm actively using it as opposed to away from. I almost always lock the screen when I step away from my computer, so I want to have the same signal do more than just start the screensaver.
The solution#
Save the follow script which is slightly modified from the example in
the man page for xscreensaver-command
as watch-xscreensaver.pl
:
#!/usr/bin/perl
my $blanked = 0;
open (IN, "xscreensaver-command -watch |");
while (<IN>) {
print;
if (m/^(BLANK|LOCK)/) {
if (!$blanked) {
system "on-xscreensaver-lock";
$blanked = 1;
}
} elsif (m/^UNBLANK/) {
system "on-xscreensaver-unlock";
$blanked = 0;
}
}
if ($blanked) {
system "on-xscreensaver-unlock";
}
Either call it from your ~/.xsessionrc
file or just
manually run from a terminal in your X session. I run it from a
screen
session so I can reattach to it and see the output:
screen -d -m -S xscreensaver-watch watch-xscreensaver.pl
My on-xscreensaver-lock
and on-xscreensaver-unlock
scripts
are below and may be a good starting place, but yours will probably be
different depending on your needs.