Closed demonguy closed 5 months ago
You need to follow the Cocoa naming convention for methods, e.g.:
class ScreenLockerListener(NSObject):
def screenLocked_(self, sender):
print("Screen locked")
def screenUnlocked_(self, sender):
print("Screen unlocked")
...
notification_center.addObserver_selector_name_object_(
sll,
"screenLocked:",
"com.apple.screenIsLocked",
None
)
notification_center.addObserver_selector_name_object_(
None,
screenUnlocked:,
"com.apple.screenIsUnlocked",
None
)
PyObjC's default translation from Python method names to ObjC selectors changes all underscores to colons, and requires that there is an argument for every colon. *args
is supported, but makes it easier to hide code problems.
Describe the bug I tried to write a program to listen "Screen Lock" event of my mac. So far it can be triggered, but I failed to write corresponding handler and get error "unrecognized selector sent to instance 0x1496c8d90" when I lock screen. Did I make anything wrong with my code?