Day 7: Set screensaver timeout from the command-line (App::SetScreensaverTimeout)
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
Here's the problem statement: For safety/privacy reason, I generally want my desktop screensaver to trigger rather quickly (say 3-5 minutes) to minimize prying eyes when I'm away or fall asleep and forget to lock. But when I watch videos, I want to set the timeout to a longer time (say the total duration of the videos plus 1 minute, or (better) 20-60 minutes which is the amount of time from I start the video until I doze off at night.
I used to have this line on my ~/.mplayer/config on my PC:
heartbeat-cmd="xscreensaver-command -deactivate &"
until I use a laptop with KDE plasma on it, which doesn't use xscreensaver by default. Plus I don't think disabling screensaver for the whole playback duration is sometimes not what I want (see above).
So I wrote set-screensaver-timeout (distributed in App-SetScreensaverTimeout). This is a CLI utility to quickly set screensaver timeout from the command-line. It supports several screensavers (GNOME, xscreensaver/XFCE, and KDE plasma), and patches to support more screensaver are welcome.
The way I currently set things up is: put this command norepeat -p daily -- set-screensaver-timeout 3 on my shell startup file to reset timeout to 3 minutes everyday, then before watching a video I invoke something like set-screensaver-timeout 30.
BTW, here's a command to play all media files on the current directory and beforehand set screensaver timeout to the total duration of the fileback (note: media-info is from the Media-Info distribution, while fsql is from App-fsql distribution and I have blogged about it once in the past):
% set-screensaver-timeout `media-info * --json --naked-res | fsql --add-json - 'SELECT SUM(duration) FROM stdin'`sec && mplayer *
To check the current timeout value, a corresponding get-screensaver-timeout utility is also provided.
Happy watching!
Leave a comment