Some notes on activating/deactivating the screensaver
Problem
I had to face the following scenario. I have a script running in the background. When a condition is fulfilled, the script opens a given webpage and takes a screenshot.
Difficulties:
- If I leave the machine alone and the screensaver gets activated, I get a beautiful black screenshot :( So first, I had to switch the screensaver off (see this post).
- Some kind of screensaver would still be useful. I can’t leave the screen on 24/7 and I don’t want to switch the monitor on/off each time I enter/leave the room.
Solution
To solve the 2nd difficulty, I came up with the following solution. I wanted a screensaver that I can activate/deactivate from a script. Under deactivation I mean that the screensaver is on, and from a script I can poke/wake up the screensaver without touching the mouse or the keyboard.
Install:
sudo apt-get install gnome-screensaver
Activate it:
gnome-screensaver-command -a
Deactivate it (demo):
gnome-screensaver-command -a && sleep 3 && gnome-screensaver-command -d
In addition, since I switched off the screensaver completely (see difficulty #1), I wanted to be able to activate the screensaver with a keyboard shortcut (with Ctrl+Alt+S for instance when I leave the room). Here is how to do it:
- Open the Keyboard utility from the Dash.
- Under the tab Shortcuts, select Custom Shortcuts. With the “
+
” button add the command “gnome-screensaver-command -a
“. Click on “Disabled” and press the new shortcut (I suggest Ctrl+Alt+S). - See this page for some screenshots.
In your script, do something like this for activating/deactivating the screensaver (pseudo code):
# The screensaver may be on or off. If it's on, I suppose # you activated it with Ctrl+Alt+S, as explained above. if (some condition is met): external_call("gnome-screensaver-command -d") make a screenshot external_call("gnome-screensaver-command -a")