Is there a program to do following: I have a webcam on my laptop. I would like that my computer starts a screensaver if I'm not watching my laptop and stop the saver when I'm watching the screen. Is there a program for reading the webcam? I'm using Ubuntu 14.04.

  • I don't know but it would be funny. Some android smartphones already do. – LatinSuD Sep 9 '14 at 12:12

From the sound of this blog post you can use the project shantz-locker.sh to do what you want.

The post includes everything you need. The 2 pieces are the use of the motion application which is typically available in most repos such as Fedora and/or Ubuntu, and the shell script that's attached to the above article, shantz-webcam-locer.zip.

NOTE: I've also posted the script on pastebin.com here, in case the original ever goes away.


./shantz-locker [-l <LockThreshold>] [-u UnlockThreshold] [-s LockScanInterval] [-t UnlockScanInterval]
  • LockThreshold – Determines the threshold (based on no. of samples sans motion) to lock your PC. Default is 5
  • UnlockThreshold – Determines the threshold (based on no. of samples with motion) to unlock your PC. Default is 2
  • LockScanInterval – How soon to check if there is motion when your PC is in unlocked state. Default interval is 5 seconds
  • UnlockScanInterval – How soon to check if there is motion when your PC is in locked state. Default interval is 2 seconds

The ZIP file contains only 2 files, a sample motion.conf file along with the script, shantz-locker.sh.

$ unzip -l shantz-webcam-locker.zip 
Archive:  shantz-webcam-locker.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  08-10-2008 12:11   shantz-webcam-locker/
    22115  08-10-2008 10:57   shantz-webcam-locker/motion.conf
     2954  08-10-2008 11:32   shantz-webcam-locker/shantz-locker.sh
---------                     -------
    25069                     3 files
  • 1
    woah, very cool @slm. Ok. now, to take yet another step toward a sentient living room... – mikeserv Sep 9 '14 at 15:18
  • Hmm. I tried that but it did not close the saver when I sat down by my computer. – noobie Sep 9 '14 at 17:50
  • @noobie Make sure that the command gnome-screensaver-command works from a shell. You're likely running into an issue with the commands used by this script to lock/unlock the screensaver. – slm Sep 9 '14 at 18:30
  • I installed the gnome-screensaver but the script still won't unlock the screensaver. – noobie Sep 10 '14 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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