Viewed 136 times
How To Make Mac Sleep
I am not looking for anything revolutionary but I am in a stage of possibly having sleep apnea and going in for my sleep study soon. I just got my watch last night and want to preliminarily start using an app to monitor heart rates during sleep, movements, etc.
I'm looking for a way to authenticate a macOS app that would allow the app to wake the user's Mac from sleep.
I'm aware that I can schedule a power event to wake the computer using similar code to what is provided here.
Mac Sleep Mode
When I run the IOPMSchedulePowerEvent code, the value of 'result' in the code below is (IOReturn) result = -536870207.
After doing some digging and finding someone with a similar issue on this forum post, I'm pretty confident that the root of my problem lies in needing to authenticate the app to allow it to wake the user's Mac from sleep. I've found some of the apple documentation for local authentication here, but it still doesn't seem to fully address my issue.
![Sleep App For Mac Sleep App For Mac](/uploads/1/2/6/0/126081454/609768779.jpg)
So, in short, how can I provide the app the authentication it needs to wake a Mac from sleep?
Edit: I've been looking into the issue some more, and I think I've been making good progress.
For starters, the reason I was getting the
kIOReturnNotPrivileged
was because you have to run the app as root in Xcode. This can be accomplished by editing the debug scheme via Product > Scheme > Edit Scheme and by changing the 'Debug Process as' option to 'Root'. Setting the app to run as root, I am able to properly schedule the power events to put my machine to sleep and wake it up at prescribed times.
There seems to be some other issues that crop up in Xcode 8.3 if you have your app sandboxed and running as root. I'll create another post to ask this question.
mgwiggles
mgwigglesmgwiggles
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.