ghiro87
ghiro87

Reputation: 29

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

Upvotes: 1

Views: 143

Answers (1)

Francesco Fattori
Francesco Fattori

Reputation: 75

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

Upvotes: 1

Related Questions