How to launch the Mac OS X screen saver from the command line with an AppleScript
Mac OS X has a built-in command line utility named "osascript" that can read and execute AppleScript files or commands passed as arguments. By using osascript to launch the Screen Saver engine, you can lock your screen from the command line:
osascript -e 'tell application id "com.apple.
ScreenSaver.Engine" to launch'
To shorten this command, you can save it as a bash script (named "launchss.sh" in this example) in your Home folder:
#!/bin/bash
osascript -e 'tell application id "com.apple.
ScreenSaver.Engine" to launch'
... and run it by entering:
sh ~/launchss.sh
Alternatively, you can make the script behave like an application by saving it with a ".command" file extension instead of ".sh". To execute it, double-click it in the Finder or drag it to your Dock and launch it from there.
More details about osascript's usage can be found in its man page:
man osascript