Web lists-archives.com

Re: Disable and Enable Screensaver via Bash Script




‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Tuesday, October 16, 2018 12:14 AM, <tomas@xxxxxxxxxx> wrote:

> On Mon, Oct 15, 2018 at 11:51:48PM +0000, Matthew Crews wrote:
>
> > Hi all,
> > Currently I am running Stretch with XFCE (window manager is XFWM4). I
> > presently use Xscreensaver for my screen saver. Caffeine indicator
> > doesn't work with XFCE as far as I've been able to tell, so if I want to
> > temporarily disable the screensaver I need to do so manually, and
> > re-enable it manually.
> > I'm wondering, is there a way to perform this feature with a bash
> > script? What I'm looking for is a bash script that does the following,
> > in sequence:
> >
> > 1.  Disable Xscreensaver
> > 2.  Run a given application
> > 3.  When the application closes, re-enable Xscreensaver
>
> "One" way to do it would be to issue periodically "xscreensaver-command -deactivate"
> while your application is running [1].
>
> Here [2] is a practical example, for video players.
>
> Enjoy
>
> [1] https://www.jwz.org/xscreensaver/man3.html
> [2] https://www.jwz.org/xscreensaver/faq.html#dvd
> -- tomás


Makes sense to me. So I would probably need to use a FOR or WHILE loop of some kind to periodically check if my application is running. Would need to play around with it.

Something else it looks like I could do is:

#!/bin/bash
xscreensaver-command -exit   # causes the xscreensaver process to close
/usr/bin/foo                 # runs my desired application
xscreensaver                 # restarts xscreensaver process

While I think my above script will work, its a more brute-force method, and if something breaks then Xscreensaver might not turn back on gracefully. The FOR or WHILE loop would probably be more elegant.

In any case, this is exactly what I was looking for. Thank you!