Is there a way to start the screensaver (and lock the screen) from a bash script?
Have you tried this?
/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine
Update for macOS High Sierra:
/System/Library/CoreServices/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine
Here is a bash script that does exactly what you are asking for: maclock
It is called from the command line as follows:
maclock
Under the covers it calls:
open -a ScreenSaverEngine
It can also be used to mute the system, or put the display to sleep:
maclock --mute --display