Sometimes it’s nice to be able to lock the Mac screen instantly.
This terminal command sends you directly to the login screen with a nice visual effect. No worries, you are still logged in, but to regain access to your Mac you have to enter your password again.
/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession -suspend
Use your favourite keyboard shortcut utility to define this script as a hotkey. I use iKey and have set ctrl-option-command-backspace to lock the screen.
The command uses Fast User Switching to present the login screen.
This works even if you haven’t enabled Fast User Switching, and it should work at least from Mac OS X 10.4 and up.