2

How do I get a program to run automatically every time I unlock the screen in Ubuntu?

1 Answer 1

3

Could be done using the dbus API

(perl example copied from http://live.gnome.org/GnomeScreensaver/FrequentlyAskedQuestions and slightly changed to catch screensaver going on and off)

my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver',member='ActiveChanged'\"";

open (IN, "$cmd |");

while (<IN>) {

    if (m/^\s+boolean true/) {

        print "*** Session is idle ***\n";

    } elsif (m/^\s+boolean false/) {

        print "*** Session is no longer idle ***\n";

    }

}

Next, allow the script to be run:

sudo chmod +x /usr/local/sbin/SCRIPTNAME.pl

Add the script to the Sessions manager (System>Preferences>Sessions) so that it starts with your login using this command:

perl /usr/local/sbin/SCRIPTNAME.pl

hope this helps

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .