1 #import "iTunesRemote.h"
3 @implementation iTunesRemote
7 return [[[iTunesRemote alloc] init] autorelease];
12 return @"iTunes Plug-in";
15 - (NSString *)information;
17 return @"Default MenuTunes plugin to control iTunes.";
27 iTunesPSN = [self iTunesPSN];
29 //Register for application termination in NSWorkspace
31 NSLog(@"iTunes Plugin loaded");
37 iTunesPSN.highLongOfPSN = kNoProcess;
39 //Unregister for application termination in NSWorkspace
43 - (int)numberOfSongsInPlaylistAtIndex:(int)index
45 return [[ITAppleEventCenter sharedCenter]
46 sendAEWithSendStringForNumber:@"cPla"
47 eventClass:@"core" eventID:@"cnte"
48 appPSN:[self iTunesPSN]];
51 - (NSString *)classOfPlaylistAtIndex:(int)index
53 //Not working yet. It returns the 4 character code instead of a name.
55 result = [[ITAppleEventCenter sharedCenter]
56 sendTwoTierAEWithRequestedKey:@"pcls"
57 fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd"
58 appPSN:[self iTunesPSN]];
62 - (int)currentPlaylistIndex
65 result = [[ITAppleEventCenter sharedCenter]
66 sendTwoTierAEWithRequestedKeyForNumber:@"pidx"
67 fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd"
68 appPSN:[self iTunesPSN]];
72 - (NSString *)songTitleAtIndex:(int)index
77 - (int)currentSongIndex
80 result = [[ITAppleEventCenter sharedCenter]
81 sendTwoTierAEWithRequestedKeyForNumber:@"pidx"
82 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
83 appPSN:[self iTunesPSN]];
87 - (NSString *)currentSongTitle
89 return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pnam"
90 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
91 appPSN:[self iTunesPSN]];
94 - (NSString *)currentSongArtist
96 return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pArt"
97 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
98 appPSN:[self iTunesPSN]];
101 - (NSString *)currentSongAlbum
103 return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pAlb"
104 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
105 appPSN:[self iTunesPSN]];
108 - (NSString *)currentSongGenre
110 return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pGen"
111 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
112 appPSN:[self iTunesPSN]];
115 - (NSString *)currentSongLength
117 return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pDur"
118 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
119 appPSN:[self iTunesPSN]];
122 - (NSString *)currentSongRemaining
124 long duration = [[ITAppleEventCenter sharedCenter]
125 sendTwoTierAEWithRequestedKeyForNumber:@"pDur"
126 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
127 appPSN:[self iTunesPSN]];
128 long current = [[ITAppleEventCenter sharedCenter]
129 sendAEWithRequestedKeyForNumber:@"pPos"
130 eventClass:@"core" eventID:@"getd"
131 appPSN:[self iTunesPSN]];
133 return [[NSNumber numberWithLong:duration - current] stringValue];
136 - (NSArray *)eqPresets;
143 [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Play"
144 appPSN:[self iTunesPSN]];
150 [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Paus"
151 appPSN:[self iTunesPSN]];
157 [self numberOfSongsInPlaylistAtIndex:1];
158 //[[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Next"
159 // appPSN:[self iTunesPSN]];
163 - (BOOL)goToPreviousSong
165 [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Prev"
166 appPSN:[self iTunesPSN]];
170 - (BOOL)switchToPlaylistAtIndex:(int)index
175 - (BOOL)switchToSongAtIndex:(int)index
180 - (BOOL)switchToEQAtIndex:(int)index
185 - (ProcessSerialNumber)iTunesPSN
187 NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];
188 ProcessSerialNumber number;
191 number.highLongOfPSN = kNoProcess;
193 for (i = 0; i < [apps count]; i++)
195 NSDictionary *curApp = [apps objectAtIndex:i];
197 if ([[curApp objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"])
199 number.highLongOfPSN = [[curApp objectForKey:@"NSApplicationProcessSerialNumberHigh"] intValue];
200 number.lowLongOfPSN = [[curApp objectForKey:@"NSApplicationProcessSerialNumberLow"] intValue];