~couchNerd ~serialOutrager ~puts2In42 ~makesPigsFly

Shantz Webcam Autolocker

· by Shantanu Goel · Read in about 2 min · (414 Words)

Sometimes I do some things that even I can’t explain why I did ‘em. Did this one in one of those times as well. This is a simple (and useless) script to monitor motion in front of your PC, auto-lock it when you are away and auto-unlock it when you come back. Kinda useless cuz there is no security aspect (read face detection etc) and any kind of motion triggers the unlock. Did it just because I was really bogged down by the shitload of work that I’ve been doing for the past few weeks (and even weekends as well), so wanted to take a break for a few minutes, and just chanced over my own “Home Security Using a Webcam and Twitter” post, so thought of doing something related to motion-detection again.


  1. Works only in linux, primarily because the motion detection software we are going to use here works only in linux, otherwise we can port the script to other platforms.

  2. You should have motion installed. If you are using Debian/Ubuntu or one of their derivatives, this is as simple as typing

sudo apt-get install motion

Otherwise, just go to the link above and download.


This is very simple.

  1. Download the zip file attached to this post and unzip somewhere preferably in your home directory.

  2. Open your terminal/command prompt. “cd” to the folder where you unzipped the zip file.

  3. Run the following command.

motion -c ./motion.conf
  1. Run the following(in a different terminal, after cd’ing to the same folder):

And that’s it. See the magic (a pretty useless one, I admit :-D) happen.


The shantz-locker.sh script takes a few options that you can use to customize the program according to your needs.

Usage: ./shantz-locker [-l ] [-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

If you liked it, or disliked it, or want to add your modifications to it, or have some cool idea that I can modify it for, just give me a shout in the comment box below.