Added methods for shuffle and repeat modes.
[MenuTunes.git] / iTunesRemote.m
index a743bb0..0a02b1b 100755 (executable)
@@ -7,17 +7,17 @@
     return [[[iTunesRemote alloc] init] autorelease];
 }
 
     return [[[iTunesRemote alloc] init] autorelease];
 }
 
-- (NSString *)title
+- (NSString *)remoteTitle
 {
 {
-    return @"iTunes Plug-in";
+    return @"iTunes Remote";
 }
 
 }
 
-- (NSString *)information;
+- (NSString *)remoteInformation
 {
 {
-    return @"Default MenuTunes plugin to control iTunes. Written by iThink Software.";
+    return @"Default MenuTunes plugin to control iTunes, by iThink Software.";
 }
 
 }
 
-- (NSImage *)icon
+- (NSImage *)remoteIcon
 {
     return nil;
 }
 {
     return nil;
 }
 - (BOOL)begin
 {
     iTunesPSN = [self iTunesPSN];
 - (BOOL)begin
 {
     iTunesPSN = [self iTunesPSN];
-
-    //Register for application termination in NSWorkspace
+    
     [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(applicationLaunched:) name:NSWorkspaceDidLaunchApplicationNotification object:nil];
     [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(applicationTerminated:) name:NSWorkspaceDidTerminateApplicationNotification object:nil];
     [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(applicationLaunched:) name:NSWorkspaceDidLaunchApplicationNotification object:nil];
     [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(applicationTerminated:) name:NSWorkspaceDidTerminateApplicationNotification object:nil];
-
+    
     return YES;
 }
 
     return YES;
 }
 
     return YES;
 }
 
     return YES;
 }
 
-- (BOOL)isAppRunning
+- (NSString *)playerFullName
 {
 {
-    NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];
-    int i,count = [apps count];
+    return @"iTunes";
+}
+
+- (NSString *)playerSimpleName
+{
+    return @"iTunes";
+}
+
+- (NSDictionary *)capabilities
+{
+    return nil;
+}
 
 
+- (ITMTRemotePlayerRunningState)playerRunningState
+{
+    NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];
+    int i;
+    int count = [apps count];
+    
     for (i = 0; i < count; i++) {
     for (i = 0; i < count; i++) {
-        if ([[[apps objectAtIndex:i] objectForKey:@"NSApplicationName"]
-                isEqualToString:@"iTunes"]) {
-            return YES;
+        if ([[[apps objectAtIndex:i] objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"]) {
+            return ITMTRemotePlayerRunning;
         }
     }
         }
     }
-    return NO;
+    return ITMTRemotePlayerNotRunning;
 }
 
 }
 
-- (PlayerState)playerState
+- (ITMTRemotePlayerPlayingState)playerPlayingState
 {
 {
-    long result = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"'----':obj { form:'prop', want:type('prop'), seld:type('pPlS'), from:'null'() }" eventClass:@"core" eventID:@"getd" appPSN:[self iTunesPSN]];
-
+    long result = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"'----':obj { form:'prop', want:type('prop'), seld:type('pPlS'), from:'null'() }" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+    
     switch (result)
     switch (result)
-          {
-          default:
-          case 'kPSS':
-                 return stopped;
-          case 'kPSP':
-                 return paused;
-          case 'kPSp':
-                 return playing;
-          case 'kPSR':
-                 return rewinding;
-          case 'kPSF':
-                 return forwarding;
-          }
-
-    return stopped;
+    {
+        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;
 }
 
 - (NSArray *)playlists
 {
     long i = 0;
-    const signed long numPlaylists = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cPly'), '----':(), &subj:()" eventClass:@"core" eventID:@"cnte" appPSN:[self iTunesPSN]];
+    const signed long numPlaylists = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cPly'), '----':(), &subj:()" eventClass:@"core" eventID:@"cnte" appPSN:iTunesPSN];
     NSMutableArray *playlists = [[NSMutableArray alloc] initWithCapacity:numPlaylists];
     NSMutableArray *playlists = [[NSMutableArray alloc] initWithCapacity:numPlaylists];
-    NSLog(@"entered playlist");
-
-          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:%lu, from:'null'() } }",(unsigned long)j];
-                 NSString *theObj = [[ITAppleEventCenter sharedCenter] sendAEWithSendString:sendStr eventClass:@"core" eventID:@"getd" appPSN:[self iTunesPSN]];
-                 NSLog(@"sent event cur %d max %d",i,numPlaylists);
-                 [playlists addObject:theObj];
-          }
-          NSLog(@"playlists end");
-          return [playlists autorelease];
+    
+    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
 {
 }
 
 - (int)numberOfSongsInPlaylistAtIndex:(int)index
 {
-    return [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:[NSString stringWithFormat:@"kocl:'cTrk', '----':obj { form:'indx', want:type('cPly'), seld:%i, from:'null'() }",index] eventClass:@"core" eventID:@"cnte" appPSN:[self iTunesPSN]];
+    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
 {
 }
 
 - (NSString *)classOfPlaylistAtIndex:(int)index
 {
-    int realResult = [[ITAppleEventCenter sharedCenter]
-                sendTwoTierAEWithRequestedKeyForNumber:@"pcls" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:[self iTunesPSN]];
-
-    if (realResult == 'cRTP') return @"radio tuner playlist";
-    else return @"playlist";
+    int realResult = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pcls" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+    
+    if (realResult == 'cRTP') {
+        return @"radio tuner playlist";
+    } else {
+        return @"playlist";
+    }
 }
 
 - (int)currentPlaylistIndex
 {
     int result;
 }
 
 - (int)currentPlaylistIndex
 {
     int result;
-    result = [[ITAppleEventCenter sharedCenter]
-                sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:[self iTunesPSN]];
+    result = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
     return result;
 }
 
 - (NSString *)songTitleAtIndex:(int)index
 {
     return result;
 }
 
 - (NSString *)songTitleAtIndex:(int)index
 {
-    return [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cTrk'), seld:%i, from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } } }",index] eventClass:@"core" eventID:@"getd" appPSN:[self iTunesPSN]];
+    return [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cTrk'), seld:long(%lu), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } } }",index] eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
 }
 
 - (int)currentSongIndex
 {
     int result;
 }
 
 - (int)currentSongIndex
 {
     int result;
-    result = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:[self iTunesPSN]];
+    result = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
     return result;
 }
 
 - (NSString *)currentSongTitle
 {
     return result;
 }
 
 - (NSString *)currentSongTitle
 {
-    return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pnam" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:[self iTunesPSN]];
+    return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pnam" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
 }
 
 - (NSString *)currentSongArtist
 {
 }
 
 - (NSString *)currentSongArtist
 {
-    return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pArt" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:[self iTunesPSN]];
+    return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pArt" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
 }
 
 - (NSString *)currentSongAlbum
 {
 }
 
 - (NSString *)currentSongAlbum
 {
-    return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pAlb" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:[self iTunesPSN]];
+    return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pAlb" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
 }
 
 - (NSString *)currentSongGenre
 {
 }
 
 - (NSString *)currentSongGenre
 {
-    return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pGen" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:[self iTunesPSN]];
+    return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pGen" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
 }
 
 - (NSString *)currentSongLength
 {
 }
 
 - (NSString *)currentSongLength
 {
-    return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pTim" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:[self iTunesPSN]];
+    return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pTim" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
 }
 
 - (NSString *)currentSongRemaining
 {
     long duration = [[ITAppleEventCenter sharedCenter]
 }
 
 - (NSString *)currentSongRemaining
 {
     long duration = [[ITAppleEventCenter sharedCenter]
-                        sendTwoTierAEWithRequestedKeyForNumber:@"pDur" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:[self iTunesPSN]];
+                        sendTwoTierAEWithRequestedKeyForNumber:@"pDur" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
     long current = [[ITAppleEventCenter sharedCenter]
     long current = [[ITAppleEventCenter sharedCenter]
-                        sendAEWithRequestedKeyForNumber:@"pPos" eventClass:@"core" eventID:@"getd" appPSN:[self iTunesPSN]];
+                        sendAEWithRequestedKeyForNumber:@"pPos" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
 
     return [[NSNumber numberWithLong:duration - current] stringValue];
 }
 
 
     return [[NSNumber numberWithLong:duration - current] stringValue];
 }
 
-- (NSArray *)eqPresets;
+- (float)currentSongRating
 {
 {
-    int i;
-    long numPresets = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cEQP'), '----':(), &subj:()" eventClass:@"core" eventID:@"cnte" appPSN:[self iTunesPSN]];
-    NSMutableArray *presets = [[NSMutableArray alloc] initWithCapacity:numPresets];
+    int realResult = [[ITAppleEventCenter sharedCenter]
+                sendTwoTierAEWithRequestedKeyForNumber:@"pRte" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
 
 
+    return realResult / 100;
+}
 
 
-          for (i = 0; i < numPresets; i++) {
-                 NSString *theObj = [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cEQP'), seld:%d, from:'null'() } }",i] eventClass:@"core" eventID:@"getd" appPSN:[self iTunesPSN]];
-                 [presets addObject:theObj];
-          }
-          return [presets autorelease];
+- (BOOL)setCurrentSongRating:(float)rating
+{
+    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"data:long(%lu), ----:obj { form:'prop', want:type('prop'), seld:type('pRte'), from:obj { form:'prop', want:type('prop'), seld:type('pTrk'), from:'null'() } ",(long)rating*100] eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN];
+    return YES;
+}
+
+- (BOOL)equalizerEnabled
+{
+    return NO;
+}
+
+- (BOOL)setEqualizerEnabled:(BOOL)enabled
+{
+    return NO;
+}
+
+- (NSArray *)eqPresets
+{
+    int i;
+    long numPresets = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cEQP'), '----':(), &subj:()" eventClass:@"core" eventID:@"cnte" appPSN:iTunesPSN];
+    NSMutableArray *presets = [[NSMutableArray alloc] initWithCapacity:numPresets];
+    
+    for (i = 1; i <= numPresets; i++) {
+        NSString *theObj = [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cEQP'), seld:long(%lu), from:'null'() } }",i] eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+        if (theObj) {
+            [presets addObject:theObj];
+        }
+    }
+    return [presets autorelease];
 }
 
 - (int)currentEQPresetIndex
 {
     int result;
     result = [[ITAppleEventCenter sharedCenter]
 }
 
 - (int)currentEQPresetIndex
 {
     int result;
     result = [[ITAppleEventCenter sharedCenter]
-                sendTwoTierAEWithRequestedKeyForNumber:@"pidx"
-                                                                                                         fromObjectByKey:@"pEQP" eventClass:@"core" eventID:@"getd"
-                                                                                                                                   appPSN:[self iTunesPSN]];
+                sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pEQP" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
     return result;
 }
 
     return result;
 }
 
+- (float)volume
+{
+    long vol = [[ITAppleEventCenter sharedCenter] sendAEWithRequestedKeyForNumber:@"pVol" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+    return vol / 100;
+}
+
+- (BOOL)setVolume:(float)volume
+{
+    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"data:long(%lu), ----:obj { form:'prop', want:type('prop'), seld:type('pVol'), from:'null'() }",(long)volume*100] eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN];
+    return NO;
+}
+
+- (BOOL)shuffleEnabled
+{
+    return NO;
+}
+
+- (BOOL)setShuffleEnabled:(BOOL)enabled
+{
+    return NO;
+}
+
+- (ITMTRemotePlayerRepeatMode)repeatMode
+{
+    return ITMTRemotePlayerRepeatOff;
+}
+
+- (BOOL)setRepeatMode:(ITMTRemotePlayerRepeatMode)repeatMode
+{
+    return NO;
+}
+
 - (BOOL)play
 {
 - (BOOL)play
 {
-    [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Play"
-                                                                                                                                                  appPSN:[self iTunesPSN]];
+    [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Play" appPSN:iTunesPSN];
     return YES;
 }
 
 - (BOOL)pause
 {
     return YES;
 }
 
 - (BOOL)pause
 {
-    [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Paus"
-                                                                                                                                                  appPSN:[self iTunesPSN]];
+    [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Paus" appPSN:iTunesPSN];
     return YES;
 }
 
 - (BOOL)goToNextSong
 {
     return YES;
 }
 
 - (BOOL)goToNextSong
 {
-    [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Next"
-                                                                                                                                                  appPSN:[self iTunesPSN]];
+    [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Next" appPSN:iTunesPSN];
     return YES;
 }
 
 - (BOOL)goToPreviousSong
 {
     return YES;
 }
 
 - (BOOL)goToPreviousSong
 {
-    [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Prev"
-                                                                                                                                                  appPSN:[self iTunesPSN]];
+    [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Prev" appPSN:iTunesPSN];
     return YES;
 }
 
     return YES;
 }
 
-- (BOOL)fastForward
+- (BOOL)forward
 {
 {
-    [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Fast"
-                                                                                                                                                  appPSN:[self iTunesPSN]];
+    [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Fast" appPSN:iTunesPSN];
     return YES;
 }
 
 - (BOOL)rewind
 {
     return YES;
 }
 
 - (BOOL)rewind
 {
-    [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Rwnd"
-                                                                                                                                                  appPSN:[self iTunesPSN]];
+    [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Rwnd" appPSN:iTunesPSN];
     return YES;
 }
 
     return YES;
 }
 
-
 - (BOOL)switchToPlaylistAtIndex:(int)index
 {
 - (BOOL)switchToPlaylistAtIndex:(int)index
 {
-    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'name', want:type('cPly'), seld:%i, from:'null'() }",index] eventClass:@"hook" eventID:@"Play" appPSN:[self iTunesPSN]];
-    return NO;
+    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'indx', want:type('cPly'), seld:long(%lu), from:() }",index] eventClass:@"hook" eventID:@"Play" appPSN:iTunesPSN];
+    return YES;
 }
 
 - (BOOL)switchToSongAtIndex:(int)index
 {
 }
 
 - (BOOL)switchToSongAtIndex:(int)index
 {
-    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'indx', want:type('cTrk'), seld:%i, from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } }",index] eventClass:@"hook" eventID:@"Play" appPSN:[self iTunesPSN]];
-    return NO;
+    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'indx', want:type('cTrk'), seld:long(%lu), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:() } }",index] eventClass:@"hook" eventID:@"Play" appPSN:iTunesPSN];
+    return YES;
 }
 
 - (BOOL)switchToEQAtIndex:(int)index
 {
 }
 
 - (BOOL)switchToEQAtIndex:(int)index
 {
-    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"data:obj { form:'name', want:type('cEQP'), seld:%i, from:'null'() }, '----':obj { form:'prop', want:type('prop'), seld:type('pEQP'), from:'null'() }",index] eventClass:@"core" eventID:@"setd" appPSN:[self iTunesPSN]];
-    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:@"data:1, '----':obj { form:'prop', want:type('prop'), seld:type('pEQ '), from:'null'() }" eventClass:@"core" eventID:@"setd" appPSN:[self iTunesPSN]];
-    return NO;
+    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"data:obj { form:'ID  ', want:type('cEQP'), seld:long(%lu), from:'null'() }, ----:obj { form:'prop', want:type('prop'), seld:type('pEQP'), from:'null'() }",index] eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN];
+    return YES;
 }
 
 - (ProcessSerialNumber)iTunesPSN
 {
     NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];
     ProcessSerialNumber number;
 }
 
 - (ProcessSerialNumber)iTunesPSN
 {
     NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];
     ProcessSerialNumber number;
-    int i, count = [apps count];
-
-              number.highLongOfPSN = kNoProcess;
-
-              for (i = 0; i < count; i++)
-                     {
-                         NSDictionary *curApp = [apps objectAtIndex:i];
-                        
-                                if ([[curApp objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"])
-                                    {
-                                               number.highLongOfPSN = [[curApp objectForKey:@"NSApplicationProcessSerialNumberHigh"] intValue];
-                                               number.lowLongOfPSN = [[curApp objectForKey:@"NSApplicationProcessSerialNumberLow"] intValue];
-                                           }
-                            }
-    return number;}
+    int i;
+    int count = [apps count];
+    
+    number.highLongOfPSN = kNoProcess;
+    
+    for (i = 0; i < count; i++)
+    {
+        NSDictionary *curApp = [apps objectAtIndex:i];
+        
+        if ([[curApp objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"])
+        {
+            number.highLongOfPSN = [[curApp objectForKey:
+                @"NSApplicationProcessSerialNumberHigh"] intValue];
+            number.lowLongOfPSN = [[curApp objectForKey:
+                @"NSApplicationProcessSerialNumberLow"] intValue];
+        }
+    }
+    return number;
+}
 
 - (void)applicationLaunched:(NSNotification *)note
 {
 
 - (void)applicationLaunched:(NSNotification *)note
 {