1

I have an old Linux problem without any solution so maybe you can help me please?!

Are there any possibilites to run a cli command/start a process through any systemd handled event after screen wake-up? Not system wake-up from suspend!!!, just after screen wake-up after screen blank as power saving function. There are endless redundant questions about the real system wake-up from standby on the net but sadly I have not found any for only power saving screen blank.

If this can not be reached by systemd, any other solution for it? Is it possible somehow or I have to simply forget such a thing?

Lot of thanks in advance for any type of help!

0

2 Answers 2

1

You can do that with xscreensaver.

From xscreensaver man:

--watch Prints a line each time the screensaver changes state: when the screen blanks, locks, unblanks, or when the running hack is changed. This option never returns; it is intended for use by shell scripts that want to react to the screensaver in some way. An example of its output would be:

BLANK Fri Nov  5 01:57:22 1999
RUN 34
RUN 79
RUN 16
LOCK Fri Nov  5 01:57:22 1999
RUN 76
RUN 12
UNBLANK Fri Nov  5 02:05:59 1999

The above shows the screensaver activating, running three different hacks, then locking (perhaps because the lock-timeout went off) then unblanking (because the user became active, and typed the correct password.) The hack numbers are their index in the `programs' list (starting with 1, not 0, as for the --select command.)

For example, suppose you want to run a program that turns down the volume on your machine when the screen blanks, and turns it back up when the screen un-blanks. You could do that by running a Perl program like the following in the background. The following program tracks the output of the --watch command and reacts accordingly:

#!/usr/bin/perl


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

Note that LOCK might come either with or without a preceding BLANK (depending on whether the lock-timeout is non-zero), so the above program keeps track of both of them.

1
0

While @mashuptwice 's answer seems also perfect, at the end I solved the 'problem' through the following thread: https://unix.stackexchange.com/questions/28181/how-to-run-a-script-on-screen-lock-unlock

Based on the thread there is a possibility to trigger just on 'screen-blank' (without real 'locked' state), but also on 'locked' status.

3
  • 1
    In order to qualify as an answer, ALL the information of the answer must be here and it should not be necessary to follow a link to learn the answer. Please fix this answer or it is likely it will be deleted. Jul 17, 2022 at 23:18
  • Next time consider adding that you use gnome, that way you can get more detailed on-point answers. Also please add all of the information into your answer, as link-only answers are not acceptable. Jul 18, 2022 at 7:18
  • Sorry for it. GNOME was originally indifference as I just asked for any generic solution. @mashuptwice your was perfect, but I thought will check the others and later stayed with them. There is no any type of critics on your help! If the self-answer is not enough currently, I will expand it more detailet if I have some more minutes for it. I'm a bit ruoutinless here, but of course there is no goal for make any problems. Jul 18, 2022 at 15:05

You must log in to answer this question.

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