We've shown you one way to lock your Mac with a keyboard shortcut, but if you'd like to do so without putting your computer to sleep, reader Scott shows us an alternative method.If you have BitTorrent downloads or other sleep-vulnerable processes running, this method of locking your computer is probably preferable to putting it to sleep. Just open up Automator and pick "Service" when it starts up. At the top of the workflow, where it says "Service receives selected text", change the "text" dropdown to "no input". Then drag the Run Shell Script action into the workflow, replacing cat in the text box with:
/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession -suspend
Once you've done that, your workflow should look like the image above.
Save the service as "Lock Screen" (or whatever you want), then open up System Preferences > Keyboard > Keyboard Shortcuts. If you click on Services in the leftmost pane and scroll down to the bottom, you'll find your new service in the list and you can assign it whatever keyboard shortcut you want. Now, when you hit that shortcut, your Mac will head into Fast User Switching mode, keeping all your programs running as normal (but requiring a password to access them again. Thanks Scott!