PDA

View Full Version : Objective-C: Getting Event Notifications From Specific Application


King Kovifor
2007-12-23, 21:52
I am making an objective-c application, for my own uses (at least for now).

What the application does is it gets the currently playing song from iTunes, Creates a Menu Bar Item (Like the time), and puts the title up there. Now, I cannot figure out how to have it automatically update the menu bar item when the track changes. I got it working with a "Force Update" function that does it pretty well, but I tried assigning it a keyboard shortcut, but I have to be within the .app to use it. Any help would be appreciated. BTW, I'm using Scripting Bridge to gather information. :)

Thanks,
King Kovifor

ShadowOfGed
2007-12-25, 02:16
Did a bit of Googling for about distributed notifications, and found this post (http://forums.macrumors.com/showthread.php?t=237855) on the MacRumors forums.

The tool they link to is fairly useful. iTunes appears to post notifications under com.apple.iTunes.playerInfo when the play state changes. Check it out. :)

King Kovifor
2007-12-26, 09:44
But doesn't that post mention for me to use Notification Watcher? But thanks. I will check out com.apple.iTunes.playerInfo.

ShadowOfGed
2007-12-26, 14:55
But doesn't that post mention for me to use Notification Watcher? But thanks. I will check out com.apple.iTunes.playerInfo.
That's just as a way to discover what notifications are being sent around the system, and to see what their contents are. Once you know that, you can register for the specific notifications you want with [NSDistributedNotificationCenter defaultCenter].

King Kovifor
2007-12-27, 11:45
Oh thanks. Guess I should find out what iTunes is. lol.

King Kovifor
2007-12-29, 12:56
Ok. I think I figured out what object to use, at least to get the notifications... But what I need to know is what values... Any help would be appreciated:

[NSDistributedNotificationCenter addObserver:self selector: name: object:];

Any help would be appreciated.

ShadowOfGed
2007-12-29, 13:53
This document should be helpful:

http://developer.apple.com/documentation/Cocoa/Conceptual/Notifications/Articles/Registering.html

King Kovifor
2007-12-30, 12:28
That is mostly what I need, and I got that down to mostly what I need. I just don't know what the notification name for a song change would be...

ShadowOfGed
2007-12-30, 13:38
As I mentioned earlier, the name of the distributed notification you want is com.apple.iTunes.playerInfo, and if you use Notification Watcher, you can see what keys and data to expect in the NSDictionary you receive with that notification.

:)

King Kovifor
2007-12-31, 16:11
Thank you! I was looking for something crazy like "iTunesSongChange". lol. Thanks!