PDA

View Full Version : [ubuntu] Start program when screensaver starts



mock
August 7th, 2008, 09:04 PM
I would like to start motion (motion detektion when the screen saver starts (ie when i'm away from the keyboard) and END when the screen saver ends.

That way i can have a motion detektor while i'm away from the computer.

Now is that possible? (i have search the forum and haven't found anything) but i think i could be possible to do this.

mock
August 9th, 2008, 08:27 PM
I found a way to do this:

make a file name screensaverchange.pl



#!/usr/bin/perl
my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver',me mber='SessionIdleChanged'\"";

open (IN, "$cmd |");

while (<IN>) {
if (m/^\s+boolean true/) {
#when screensaver activates, run the following commands
system("motion -n &");
} elsif (m/^\s+boolean false/) {
#when screensaver deactivates, run the following commands
system("killall -9 motion");
}
}




then



chmod +x screensaverchange.pl


to start you just have to



perl screensaverchange.pl


which you can put in your session starter,