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
48 - (int)currentSourceIndex
53 - (NSArray *)playlistsForCurrentSource
58 - (int)currentPlaylistIndex
61 result = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pidx"
62 fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd"
63 appPSN:[self iTunesPSN]];
64 NSLog(@"result: %@", result);
68 - (NSString *)songTitleAtIndex
73 - (int)currentSongIndex
76 result = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pidx"
77 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
78 appPSN:[self iTunesPSN]];
79 NSLog(@"result: %@", result);
83 - (NSString *)currentSongTitle
85 return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pnam"
86 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
87 appPSN:[self iTunesPSN]];
90 - (NSString *)currentSongArtist
92 return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pArt"
93 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
94 appPSN:[self iTunesPSN]];
97 - (NSString *)currentSongAlbum
99 return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pAlb"
100 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
101 appPSN:[self iTunesPSN]];
104 - (NSString *)currentSongGenre
106 return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pGen"
107 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
108 appPSN:[self iTunesPSN]];
111 - (NSString *)currentSongLength
113 return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pDur"
114 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
115 appPSN:[self iTunesPSN]];
118 - (NSString *)currentSongRemaining
120 NSString* duration = [[ITAppleEventCenter sharedCenter]
121 sendTwoTierAEWithRequestedKey:@"pDur"
122 fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd"
123 appPSN:[self iTunesPSN]];
124 NSString* current = [[ITAppleEventCenter sharedCenter]
125 sendAEWithRequestedKey:@"pPos"
126 eventClass:@"core" eventID:@"getd"
127 appPSN:[self iTunesPSN]];
128 NSLog(@"%@ %@", duration, current);
129 //return [[NSNumber numberWithInt:duration - current] stringValue];
133 - (NSArray *)eqPresets;
140 [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Play"
141 appPSN:[self iTunesPSN]];
147 [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Paus"
148 appPSN:[self iTunesPSN]];
154 [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Next"
155 appPSN:[self iTunesPSN]];
159 - (BOOL)goToPreviousSong
161 [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Prev"
162 appPSN:[self iTunesPSN]];
166 - (BOOL)goToNextPlaylist
171 - (BOOL)goToPreviousPlaylist
176 - (BOOL)switchToSourceAtIndex:(int)index
181 - (BOOL)switchToPlaylistAtIndex:(int)index
186 - (BOOL)switchToSongAtIndex:(int)index
191 - (BOOL)switchToEQAtIndex:(int)index
196 - (ProcessSerialNumber)iTunesPSN
198 NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];
199 ProcessSerialNumber number;
202 number.highLongOfPSN = kNoProcess;
204 for (i = 0; i < [apps count]; i++)
206 NSDictionary *curApp = [apps objectAtIndex:i];
208 if ([[curApp objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"])
210 number.highLongOfPSN = [[curApp objectForKey:@"NSApplicationProcessSerialNumberHigh"] intValue];
211 number.lowLongOfPSN = [[curApp objectForKey:@"NSApplicationProcessSerialNumberLow"] intValue];