.
Two other building blocks seem to be

Code:
xscreensaver-command -watch
and the following perl program, which tracks the output of the -watch command
and reacts accordingly:

Code:
    #!/usr/bin/perl
    my $blanked = 0;
    open (IN, "xscreensaver-command -watch |");
    while (<IN>) { 
       if (m/^(BLANK|LOCK)/) { 
           if (!$blanked) { 
#              **** action to take when screensaver starts ****
               $blanked = 1;
           }
       } elsif (m/^UNBLANK/) {
#              **** action (if any) to take when screensaver is reset ****
               $blanked = 0;
       } 
    }
I don't think perl should be necessary, and there is probably a simpler
bash equivalent that would suffice.