MacOS: How to prevent screen blanker

isotopp image Kristian Köhntopp -
July 30, 2022
a featured image

When running Keynote, MacOS prevents the screen blanker from kicking in. I needed a similar thing in one of my Python applications, so I needed to find out how it does that.

It turns out, there is an API for that: beginActivity:withOptions: , which returns an Object token activity. Calling endActivity with that Token ends the activity, and resumes the screen blanker countdown.

There is a list of activity options, NSActivityOptions . We are interested into NSActivityIdleDisplaySleepDisabled and NSActivityUserInteractive, mostly.

Interfacing with Objective-C in Python is possible through ctypes, but that is work. Work, it turns out, that has already been done in appnope , specifically in _nope.py .

Integrating that into my PyQt application is trivial.

Share