This cron job is intended for people who want their Mac to auto-lock after inactivity period, but can't define the Screen Saver "Start after:" parameter (in my case - because of a Mac configuration profile enforced by my employer). It requires you set your Mac to lock when screen saver starts. Your Mac won't lock if there's something preventing it from sleeping, like watching a video.
screensaver_cron.shto your favorite executable path (e.g
chmod +x ~/bin/screensaver_cron.sh
In order to make this script run periodically, you need to define it as a cron job. Do that by editing your crontab file:
env EDITOR=vim crontab -e
- Add the following line to the prompted editor:
* * * * * /Users/<youruser>/bin/screensaver_cron.sh(replace with your Mac username).
The 5 asterisks in the beginning of the line mean this script will every minute (lowest resolution a cron task can run in). Feel free to change the cron timing parameters to suit your needs.
The script itself is set to launch screen saver after 60 seconds of inactivity. It's defined within the script in an easy-to-change variable.