Jump to content

Objective-C: Fetching Events


6 posts in this topic

Recommended Posts

Hey,

 

I am a relatively new programmer, and by that I mean I am new to OS X programming. I do a ton of non-OS X programming. But to get to the point.

 

My current project is a small and tiny application that fetches the currently playing song from iTunes. I have the retrieval part with a ton of trial in error. I did this through scripting bridge, that new framework introduced within Leopard. Once the application is launched, I have to manually refresh the currently playing song from iTunes to have it shown in the menu bar...

 

Is there anyway to have a function (- (IBAction)updateData;) be called anytime that the song changes within iTunes? That way no manual interaction is required from the user. I have spent the whole day trying to get this working. I got the scripting bridge and updating of the menu bar item done this morning after a bit of messing.

 

Any help would be appreciated,

King Kovifor

Link to comment
Share on other sites

You can do it automatically... Here is the code:

 

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

 

Don't forget to remove the request for notifications with:

 

	[[NSNotificationCenter defaultCenter] removeObserver:self];

 

I suggest that bit in a -(void)dealloc {} overwrite then [super dealloc];!

Link to comment
Share on other sites

 Share

×
×
  • Create New...