screen lock using a script Is it possible to lock the screen in OS Yosemite using code? And then put in a scheduler to run every two minutes?

If so what script language are we talking, task scheduler program etc
Here is the way I would try completing this task: 


Create a script file that will be executed every time the system starts: 



sudo nano ~/sleep.sh




Input the following text in the file: 



#!/bin/bash
sleep 120
pmset sleepnow
#osascript -e 'tell application "System Events" to sleep'



Note: The last line with the # at the front is a substitute of the one above (pmset sleepnow)


Open the CronJob editor in order to start the script frequently: 



  env EDITOR=nano crontab -e



Input rule for the script to be started automatically



  * * * * * sh ~/sleep.sh



Re/start the current CronJobs: 



  sudo touch /private/etc/crontab


P.S. I haven't tested it, but I will gladly help if anything additional is needed.