In OS X 10.9 and later:
By itself, this command only causes the display to sleep, resulting in a black screen. By configuring your computer to require a password immediately after sleep, this one-liner works as a "lock computer" command. The preference is available at System Preferences > Security & Privacy > General.
Source: How ...
Note: This solution is unique in that it uses the Keychain Access menu bar status functionality, but it does not require you to enable the Show keychain status in menu bar option as the AppleScript methods do.
I was also looking for a solution for this. Today I just had some time to play around and found a way to programmatically actually call the ...
Logging out to the fast user switching screen
Run /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend.
Enable the fast user switching menu from the Users & Groups preference pane and then select Login Window… from the menu.
Use the lock action in Alfred.
Locking the screen
Check "Require password immediately after ...
It's because the sleeve has a "Magnetic snap closure with no zippers" which actually mimics the magnetic latch that's triggered while the lid of the MacBook is closed which turns off the screen.
I've noticed this happen to me a few times in different situations when I would put my iPhone on the hand rest part of the MacBook or If i left my Adonit Jot Pro(...
Edit: pressing the power key on a MacBook Air while holding control and shift does not work in 10.7. The power key can only be substituted for eject in 10.8 and later versions of OS X.
Putting displays to sleep only locks the screen if this setting is enabled:
You can also put displays to sleep in 10.9 by running pmset displaysleepnow.
Another way to lock ...
You can set up a hot corner for screen saver, and have the security settings to require your password immediately after the screen saver starts. This means when you go to leave the computer, you just move the mouse to a specified corner of the screen and BAM it's locked.
First, you would open System Preferences, and then go to "Desktop & Screen saver". ...
The Lock Screen for keychain no longer is available in current version of the MacOS Mojave & High Sierra.
Apple have now add a Lock Screen Menu item in the Apple menu.
This has the default keyboard short cut of crtl + cmd + Q
------------- Old answer for previous OS below --------------
@Bart Arondson answer goes into using some ...
Use a keyboard shortcut and use Automator to make a screen lock service. This will allow you to set any keyboard command you would like to lock or start a screen saver on your mac. As referenced below is a nice article on how to do the process.
Handy screen locking tips for Mac
If mousing to part of the screen isn’t your thing, you can use the keyboard ...
I just found that I could lock my screen using the following shortcut:
Control ⌃+Shift ⇧+Power ⌽
Require password immediately after sleep or screen saver begins should be checked in the Security & Privacy in System Preferences panel if you want to ensure a slept screen is also securely locked.
MacBook Air replaces eject button with power button. Use this instead:
Update 2013-11-23: I apologize for not reading the question carefully. I missed the part where you want to actually lock the screen. The combination key below only turn off the screen without actually locking it.
If you want to enter sleep mode (where ...
Getting information from this answer and this answer:
Press the Spotlight button at the top right of the screen (Cmd + Space)
Search Keychain Access. Open this
Open Preferences (Cmd + ,(comma))
Check Show Status in Menu Bar
Press the Spotlight button at the top right of the screen (Cmd + Space)
Search Automator. Select this
Create new Service
Search Run ...
KeepingYouAwake is a free and open source app that can be used for this purpose.
The intended purpose of this app is to prevent your Mac from going into sleep. You can activate this app from 5/15/30 minutes to 1/2/5 hours to indefinite duration.
Having KeepingYouAwake activated will prevent screen from turning off when lock screen mode is activated.
The easiest way to go about this without jailbreaking is to use some custom wallpaper.
Make a new document in Photoshop, Pixelmator, GIMP, or your editor of choice.
Find a high-resolution image on the Web that you like and copy it into the document. Crop it to 640 x 960 pixels.
Add some text with your personal info over the image. Make sure that you leave ...
You can use Guided Access to restrict access to a single app, and even ignore touch on certain (or all) parts of the screen.
To enable, first go to Settings > General > Accessibility > Guided Access. Then once you're in the app, just triple tap the home button.
See iOS: About Guided Access for more information or check out this short video.
Since at the login window (and the lock screen) your user is not logged in, you´ll have to edit the global preferences:
sudo defaults write /Library/Preferences/.GlobalPreferences AppleLocale en_GB
sudo defaults write /var/root/Library/Preferences/.GlobalPreferences AppleLocale en_GB
and then do a reboot. This fixed it for me (and I hope, Apple ...
Set the preferences to lock the screen when the screen saver is active.
Then you can use this terminal command to start the screen saver.
As far as I can tell this is exactly what the Keychain menu item does.
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" ...
Launch Terminal and run:
ifconfig | grep -B 6 'status: active' | head -n 1 | cut -d : -f 1
Then run (replace en0 below with the output of the command above):
sudo ./airport en0 prefs DisconnectOnLogout=NO
sudo pmset -a sleep 0
I am on MacOS Mojave (...
EDIT: With macOS High Sierra (as of beta 5) you can achieve the same "lock screen" behaviour mentioned by @Phong simply through the status bar menu:
What I think is happening is that your computer goes to sleep after a certain amount of time after you switched to the login window which causes your script to stop.
To prevent your system from sleeping ...
Just follow these steps to lock the screen on macOS.
In Spotlight (⌘ + Space) search for Keychain Access
In Keychain Access, select Preferences... from the first menu (⌘ + ,)
Check Show keychain status in menu bar. This will show a lock in your Menu Bar with an option Lock Screen
Add a custom shortcut to lock the screen
System Preferences > Keyboard &...
Yes - the frame buffer should be scrubbed / discarded as part of the sleep / lock process no matter how brief the render. I don't think it's a huge risk and can be mitigated as you say by logging out of the screen before locking or any number of other ways like timed lockouts.
I'd just log out or enable fast user switching and switch away from the screen ...
The easiest way to lock your computer is to set require password immediately and turn off the display with the following key combination:
control + shift + power
I find this super helpful and a great replacement for ctrl + shift + delete in Windows.