NSSystemClockDidChangeNotification never fires

Issue #250 resolved
Marianna Budnikova
created an issue

Hi,

I am trying to subscribe to NSSystemClockDidChangeNotification and it never seems to fire. I used the example you have here to subscribe to the notification by replacing the NSWorkspaceDidMountNotification with NSSystemClockDidChangeNotification, but the notification seems to not fire when I change the time in Date&Time panel.

Thanks! Ri

Comments (3)

  1. Ronald Oussoren repo owner

    Never mind: I do known what's going wrong.

    The example script uses a notification center that's specific to the workspace and not the regular application notification center.

    The following script works for me:

    from Foundation import *
    from PyObjCTools import AppHelper
    
    class NotificationHandler (NSObject):
      def handleNotification_(self, aNotification):
         print("System time changed", aNotification)
    
    notificationCenter = NSNotificationCenter.defaultCenter()
    notificationHandler = NotificationHandler.alloc().init()
    notificationCenter.addObserver_selector_name_object(
       notificationHander,
       "handleNotification:",
       NSSystemClockDidChangeNotification,
       None)
    
    AppHelper.runConsoleEventLoop() 
    
  2. Marianna Budnikova reporter

    Awesome, thank you for helping out, Ronald!

    I had to modify the observer call a little bit (maybe since I have a different library version) and it worked like a charm!

    notificationCenter._addObserver_selector_name_object_options_(
       notificationHander,
       "handleNotification:",
       NSSystemClockDidChangeNotification,
       None,
       0)
    
  3. Log in to comment