Search code examples
cocoainputpollingscripting-bridge

Cocoa ScriptingBridge Input Polling


I am trying to use ScriptingBridge to write a small iTunes controller. The problem is to find an efficient way of getting notifyed whenever any changes occur. My first approch was to poll the input in a loop and just keep checking for differences. But I think there must be a more efficient way of getting notifyed about input!

Thanks in advance!


Solution

  • iTunes sends out a notification when something changes so just register for it in your init method of AppDelegate. Here's an example...

    [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(receivediTunesNotification:) name:@"com.apple.iTunes.playerInfo" object:nil];
    

    The actual notifcation object in your method "receivediTunesNotification:" will contain information about the changes.