Can I make automatic log-out when Mac is asleep?

I'd like to have my MacBook Pro to automatically log out when it hasn't been used for a certain period of time, e.g., 30 minutes. I defined my System Preferences to do so when it's "inactive" for that period of time. However, it doesn't seem to automatically log out if I close the lid when I'm done working. For example, if I close my lid and my Mac sleeps overnight, opening the lid in the morning shows me the account that was last logged in.

macOS System Preferences

Does sleeping prevent a Mac from logging out automatically? From my point of view, sleeping is the ultimate form of inactivity.

If the above is true, is there a way to make my Mac to automatically log out despite its sleep state? Or could I even force it to log out immediately when it goes to sleep?

I see many questions on this site and other sites that talk about ways to prevent automatic sleep or log-out behavior, but not anything about my issue. FYI, I'm running macOS 10.11 (El Capitan).


Solution 1:

Yes, a sleeping Mac will prevent your account being logged out.

From a running process or application's perspective, time stops while the computer is asleep. Developers of applications need to actively monitor sleep wake cycles and adjust their timers accordingly. Many applications do not.

Third Party Tools

You can use third party software to log out before sleep or after a period of inactivity.

enter image description here

Power Manager, which is a product I work on, is able to trigger a log out on sleep, after inactivity, or immediately upon wake. Given you are running macOS 10.11, be sure to try the appropriate legacy version.

Be aware that performing actions on sleep is generally not advisable.