+ NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];
+ int i;
+ int count = [apps count];
+
+ for (i = 0; i < count; i++) {
+ if ([[[apps objectAtIndex:i] objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"]) {
+ return ITMTRemotePlayerRunning;
+ }
+ }
+ return ITMTRemotePlayerNotRunning;
+}
+
+- (ITMTRemotePlayerPlayingState)playerPlayingState
+{
+ long result = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"'----':obj { form:'prop', want:type('prop'), seld:type('pPlS'), from:'null'() }" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+
+ switch (result)
+ {
+ default:
+ case 'kPSS':
+ return ITMTRemotePlayerStopped;
+ case 'kPSP':
+ return ITMTRemotePlayerPlaying;
+ case 'kPSp':
+ return ITMTRemotePlayerPaused;
+ case 'kPSR':
+ return ITMTRemotePlayerRewinding;
+ case 'kPSF':
+ return ITMTRemotePlayerForwarding;
+ }
+
+ return ITMTRemotePlayerStopped;
+}
+
+- (NSArray *)playlists
+{
+ long i = 0;
+ const signed long numPlaylists = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cPly'), '----':(), &subj:()" eventClass:@"core" eventID:@"cnte" appPSN:iTunesPSN];
+ NSMutableArray *playlists = [[NSMutableArray alloc] initWithCapacity:numPlaylists];
+
+ for (i = 1; i <= numPlaylists; i++) {
+ const long j = i;
+ NSString *sendStr = [NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cPly'), seld:long(%lu), from:'null'() } }",(unsigned long)j];
+ NSString *theObj = [[ITAppleEventCenter sharedCenter] sendAEWithSendString:sendStr eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+ [playlists addObject:theObj];
+ }
+ return [playlists autorelease];
+}
+
+- (int)numberOfSongsInPlaylistAtIndex:(int)index
+{
+ return [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:[NSString stringWithFormat:@"kocl:type('cTrk'), '----':obj { form:'indx', want:type('cPly'), seld:long(%lu), from:'null'() }",index] eventClass:@"core" eventID:@"cnte" appPSN:iTunesPSN];
+}
+
+- (NSString *)classOfPlaylistAtIndex:(int)index
+{
+ int realResult = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pcls" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+
+ if (realResult == 'cRTP') {
+ return @"radio tuner playlist";
+ } else {
+ return @"playlist";
+ }