programmically lock system mac OS

I am recreating screen saver type functionality in my mac OS app. My app requirements are to run on 10.11 and up.


I am looking for a good way to call the lock screen. I have tried 5 or 6 different ways and the best I can do it sleeping the computer which, if the user has "require password" in system prefs it will lock.

my only current solution is a shell call to "pmset sleepnow", even "pmset displaysleepnow" fails.

Can I ask why you want to do this? Historically, this behavior had two purposes:


1. Locking access after a certain time period.


2. Preventing screen burn-in.


Currently, both of these things can be done directly from System Preferences. In fact, #2 now tends to be done by putting the display to sleep, rather than using a screen saver, for energy efficiency reasons.


Given that users can configure these exactly how they wish, without your app, what purpose does your app serve? Why does your app need to lock the user out of other apps? If your app is providing security, how you know it's actually more secure than what users can already do with built-in functionality? (If not, why should they use your app?)


Maybe you have really good reasons for doing this. If so, telling us more about your reasons may help us suggest a more acceptable solution.

I have a "screen saver" app in the app store. Since Apple does not allow us to submit and actual screen saver plugin to the app store, what many developers do such as myself is recreate most of the preference pane functionality in an executable. Search the app store for "screen saver" and you will see a large number of examples.


Currently, my app has the functionality to take over the screen and display its animation after a certain amount of user-specified idle time. Then, when the user moves the mouse or presses a key, I return them back to their previous screen. All of this works great, but I would like to add a new preference / feature to the app so that before returning user control, I would programatically lock the system like the system preferences screen saver plugins do. Ideally, I would read the users preference for this, but since my app is sandboxed away from reading it, thats another problem to solve. For now, I will present a user prefence for locking after the screen saver returns.


Any chance you have an answer to the original question ? I am fully aware that this can be accomplished with built-in tools, I wish to re-create it in my own code.

I don't have the answer, but since you've clarified your scenario there's a better chance that someone else will jump in and help.


OTOH, since you are not a beginner, I think a better approach is to use a TSI to get a definitive answer. Better to ask the people who do know than to ask the people who don't.

I will try a TSI, an Apple engineer is more likely to have a solution.

programmically lock system mac OS
 
 
Q