Here's something for anyone who, like me, scoured the web for a simple Mac equivalent to "Windows-L" to lock the screen, and found that all the solutions either required third-party software you don't want or a special key that doesn't exist on your (generic external) keyboard. The following worked for me in Mavericks (10.9.3)
- Launch the "Automator" application and create a new document of type "Service"
- Specify that the service receives "no input" in "any application"
- Add the "Run Shell Script" action to the service
- Paste the following into the "Run Shell Script" action's text area:
- Save the service as "Start ScreenSaver" and quit Automator
- Launch the "System Preferences" application and go to the "Security" preference pane
- Under the "General" tab, enable "Require password [immediately] after sleep or screen saver begins"
- Now go to the "Keyboard" preference pane, "Shortcuts" tab, "Services" list item, and find your "Start ScreenSaver" service under "General" near the bottom of the list on the right, and double-click it.
- Press your chosen keyboard shortcut (I like control + option + command + L, so I can just mash all three modifier keys together and hit L for lock)
EDIT: I had trouble after an upgrade to OSX El Capitan. I was using the more-succinct AppleScript content:
activate application "ScreenSaverEngine"
which I thought should have been more future-proof than the shell-script incantation of step 4, but the first time I used it, it claimed to be unable to find ScreenSaverEngine. This was fixed after I started
ScreenSaverEngine.app once explicitly from the command-line: