Get windows preventing sleep in swift macOS
I'm developing a Swift application for macOS and I would like to retrieve the list of windows that are preventing Sleep. Like the column in Activity Monitor->Energy. Is there a way to retrieve this attribute in Swift? Thank you
Solution 1:
Yes, you can do this with:
var assertions: Unmanaged<CFDictionary>?
if IOPMCopyAssertionsByProcess(&assertions) != kIOReturnSuccess {
fatalError("Error with assertions")
}
and in there you can find various assertions, and also Prevent screen dim and system stop