For both battery-life and environmental reasons, I prefer my MacBook (Sierra) to enter sleep mode fairly quickly if I'm not using it. For security reasons, I would like for it always to require a password when it's opened. But it seems like the only way to make it lock when closed is to make require a password every time it goes into sleep mode.
Meanwhile (also for security purposes), I have a pretty long/random password — one I don't want to have to enter every time I leave my computer for five minutes. Surely I don't have to choose between security and battery life?
It seems like both would be pretty standard concerns for Mac users. All I want is for my machine not to require a password when it wakes up, and to require one whenever it's reopened.
Is there a way to achieve what I want?
Best Answer
You'll need to run a command that locks the Mac when the lid is closed that means when Mac goes to sleep, the command that needs to execute every time the Mac goes to sleep is:
To run a command when the Mac goes to sleep you can use Sleepwatcher you have at least two options to install it:
brew install sleepwatcher
, if you are familiar with some linux flavor then this is like the package managerapt-get
for Ubuntu ordnf
for Fedora and so on.After installing
sleepwatcher
you'll need to decide if you want to run it like a daemon or by command line:Running by command line:
Maybe you'll need to change the path to
sleepwatcher
Parameter
-s
, taken from man page:The command needs to be between quotation marks
With this option you'll need to run
sleepwatcher
manually on every logoff, restart or shutdown.If you decide to run
sleepwatcher
as a daemon, then you'll need to create or modify (in case you download the program from the web) aplist
file that works as a configuration file to start a daemon, the plist file that I modify looks like:To start the
sleepwatcher
as a daemon you'll need to run the following command:You'll need to change the path to the
plist
file, the location of this file should be at:or
The first path is to run
sleepwatcher
for all users, the second path is to run per user.With this option
sleepwatcher
starts and stops automatically on every logoff, restart or shutdown.