+- (BOOL)isAppRunning
+{
+ NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];
+ int i,count = [apps count];
+
+ for (i = 0; i < count; i++) {
+ if ([[[apps objectAtIndex:i] objectForKey:@"NSApplicationName"]
+ isEqualToString:@"iTunes"]) {
+ return YES;
+ }
+ }
+ return NO;
+}
+
+- (PlayerState)playerState
+{
+ 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 stopped;
+ case 'kPSP':
+ return playing;
+ case 'kPSp':
+ return paused;
+ case 'kPSR':
+ return rewinding;
+ case 'kPSF':
+ return forwarding;
+ }
+
+ return stopped;
+}
+
+- (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 fixForAECrappiness:i];
+ [playlists addObject:theObj];
+ }
+ return [playlists autorelease];
+}
+