macOS UIApplication not in scope

I'm trying to disable the sleep timer when a button is pressed in my macOS app but the problem is that from the resources I've seen elsewhere the code doesn't work.

The code I'm trying is

UIApplication.shared.isIdleTimerDisabled = true

When I try and run my app I get this error

Cannot find 'UIApplication' in scope

From what I've managed to search for regarding this it appears that UIApplication might be an iOS thing, but how can I adapt this for macOS? I've found some code samples from 5+ years ago but it involves lots of code. Surely, in 2025 macOS can disable sleep mode as easy as iOS, right?

How can I achieve this please?

A quick search points me to the ProcessInfo class and its beginActivity(options:reason:) and endActivity(_:) methods. The options you can pass to beginActivity include preventing sleep. See the documentation for ProcessInfo for more details and examples.

And yes, UIApplication is specific to iOS.

macOS UIApplication not in scope
 
 
Q