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
45 //This is probably unneeded
49 - (int)currentSourceIndex
51 //This is probably unneeded
55 - (NSArray *)playlistsForCurrentSource
57 //This is probably unneeded
61 - (NSString *)sourceTypeOfCurrentPlaylist
63 //Not working yet. It returns the 4 character code instead of a name.
65 result = [[ITAppleEventCenter sharedCenter]
66 sendTwoTierAEWithRequestedKey:@"pcls"
67 fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd"
68 appPSN:[self iTunesPSN]];
72 - (int)currentPlaylistIndex
75 result = [[ITAppleEventCenter sharedCenter]
76 sendTwoTierAEWithRequestedKeyForNumber:@"pidx"
77 fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd"
78 appPSN:[self iTunesPSN]];
82 - (NSString *)songTitleAtIndex
87 - (int)currentSongIndex
90 result = [[ITAppleEventCenter sharedCenter]
91 sendTwoTierAEWithRequestedKeyForNumber:@"pidx"
92 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
93 appPSN:[self iTunesPSN]];
97 - (NSString *)currentSongTitle
99 return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pnam"
100 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
101 appPSN:[self iTunesPSN]];
104 - (NSString *)currentSongArtist
106 return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pArt"
107 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
108 appPSN:[self iTunesPSN]];
111 - (NSString *)currentSongAlbum
113 return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pAlb"
114 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
115 appPSN:[self iTunesPSN]];
118 - (NSString *)currentSongGenre
120 return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pGen"
121 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
122 appPSN:[self iTunesPSN]];
125 - (NSString *)currentSongLength
127 return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pDur"
128 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
129 appPSN:[self iTunesPSN]];
132 - (NSString *)currentSongRemaining
134 long duration = [[ITAppleEventCenter sharedCenter]
135 sendTwoTierAEWithRequestedKeyForNumber:@"pDur"
136 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
137 appPSN:[self iTunesPSN]];
138 long current = [[ITAppleEventCenter sharedCenter]
139 sendAEWithRequestedKeyForNumber:@"pPos"
140 eventClass:@"core" eventID:@"getd"
141 appPSN:[self iTunesPSN]];
143 return [[NSNumber numberWithLong:duration - current] stringValue];
146 - (NSArray *)eqPresets;
153 [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Play"
154 appPSN:[self iTunesPSN]];
160 [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Paus"
161 appPSN:[self iTunesPSN]];
167 [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Next"
168 appPSN:[self iTunesPSN]];
172 - (BOOL)goToPreviousSong
174 [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Prev"
175 appPSN:[self iTunesPSN]];
179 - (BOOL)goToNextPlaylist
181 //This is probably unneeded
185 - (BOOL)goToPreviousPlaylist
187 //This is probably unneeded
191 - (BOOL)switchToSourceAtIndex:(int)index
193 //This is probably unneeded
197 - (BOOL)switchToPlaylistAtIndex:(int)index
202 - (BOOL)switchToSongAtIndex:(int)index
207 - (BOOL)switchToEQAtIndex:(int)index
212 - (ProcessSerialNumber)iTunesPSN
214 NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];
215 ProcessSerialNumber number;
218 number.highLongOfPSN = kNoProcess;
220 for (i = 0; i < [apps count]; i++)
222 NSDictionary *curApp = [apps objectAtIndex:i];
224 if ([[curApp objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"])
226 number.highLongOfPSN = [[curApp objectForKey:@"NSApplicationProcessSerialNumberHigh"] intValue];
227 number.lowLongOfPSN = [[curApp objectForKey:@"NSApplicationProcessSerialNumberLow"] intValue];