Objective-C, constantly run method whilst Mac OS X application is running

372 views Asked by At

i'm currently writing an application in Objective-C which displays the artist name of the song currently being played in iTunes, however i want the artist name to update when the song changes.

This is the method i have so far which gets the artist name and sets a NSTextField to display the artist name.

 - (void)updateArtistName {
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
     NSString *artistNameString = [NSString stringWithFormat:@"%@", [[iTunes currentTrack] artist]];
     [artistName setStringValue:artistNameString];}

Any help would be much appreciated, thanks, Sami.

1

There are 1 answers

3
Logan Bailey On BEST ANSWER

What you're looking for is: NSDistributedNotificationCenter. http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Notifications/Articles/Registering.html

To figure out which notifications Itunes is sending most people suggest using: https://github.com/kballard/NotificationWatcher