For a recent MacOS project I had to hook into the system screen wake and sleep notifications. This is
handled with the notification center in NSWorkspace.
There are two implementations of addObserver. The first takes a #selector argument and depends on an @objc callback. The second takes slightly different arguments, ending with a callback closure that does not depend on @objc.