Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I leave work, I lock my machine with ctrl + l to lock the screen. When I come back, I always forget to log into jabber. Is there a way to run a command after the screen is unlocked? This is in KDE. I'm not sure if the locking mechanism is an X feature or a KDE feature, so I'm not sure where to look.

share|improve this question

I had a desire to make banshee (the Gnome music player) pause/unpause when the screen was locked/unlocked. I found a ticket in the banshee launchpad project:


Someone had created a script which would notice (via DBus) if the screen was (un)locked and would trigger banshee to (un)pause. I added a small tweak to this script and have been using it for a while. I added my updated copy to that ticket.

Now I know this isn't exactly what you want to do. But you could probably take that python script (which is already detecting screen locks/unlocks) and alter it slightly to do what you would like to do. It is also my understanding that the KDE screensaver supports the same DBus interface as the gnome screensaver. It seems like the best documentation for the KDE side of things is here:


Good luck!

share|improve this answer
So is the lock screen considered a screen saver? – Falmarri Jul 11 '11 at 17:15
Yeah. I mean, I'm pretty sure they both produce the same event in DBus. – Mark Drago Jul 11 '11 at 21:58
For KDE users, substitute "org.freedesktop.ScreenSaver" for the Gnome specific string on the second last line of the script. – casualunixer Feb 9 '13 at 16:44

For the XScreenSaver the solution is xscreensaver-command -watch

man xscreensaver-command contains an example Perl script to handle various screensaver and screen lock events, like BLANK, LOCK, UNBLANK etc.

Here it is - the example turning sound off and on with the screensaver:


       my $blanked = 0;
       open (IN, "xscreensaver-command -watch |");
       while (<IN>) {
           if (m/^(BLANK|LOCK)/) {
               if (!$blanked) {
                   system "sound-off";
                   $blanked = 1;
           } elsif (m/^UNBLANK/) {
               system "sound-on";
               $blanked = 0;

Not sure if KDE uses XScreenSaver though.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.