- going to need a different way of defining key combos
¥ Optimize, this thing is big and slow :(
¥ Apple Events! Apple Events! Apple Events!
-
-¥ I think I found a slight memory leak:
- 425 MenuTunes 7.8% 8:29.87 1 56 4827 215M+ 3.14M 135M- 599M+
*/
#import "MenuTunes.h"
[menu addItem:[NSMenuItem separatorItem]];
}
}
+
curTrackIndex = -1; //Force update of everything
[self timerUpdate]; //Updates dynamic info in the menu
Size length;
NSString *result;
Ptr buffer;
+ ComponentInstance myComponent = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
script = [NSString stringWithFormat:@"tell application \"iTunes\"\n%@\nend tell", script];
AECreateDesc(typeChar, [script cString], [script cStringLength],
&scriptDesc);
- OSADoScript(OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype), &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
+ OSADoScript(myComponent, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
length = AEGetDescDataSize(&resultDesc);
buffer = malloc(length);
AEGetDescData(&resultDesc, buffer, length);
AEDisposeDesc(&scriptDesc);
AEDisposeDesc(&resultDesc);
+ CloseComponent(myComponent);
result = [NSString stringWithCString:buffer length:length];
if (![result isEqualToString:@""] &&
([result characterAtIndex:0] == '\"') &&
{
result = [result substringWithRange:NSMakeRange(1, [result length] - 2)];
}
- [script release];
free(buffer);
buffer = NULL;
return result;
- (void)timerUpdate
{
int pid;
+
if (GetProcessPID(&iTunesPSN, &pid) == noErr)
{
int trackPlayingIndex = [[self runScriptAndReturnResult:@"return index of current track"] intValue];
+
if (trackPlayingIndex != curTrackIndex)
{
[self updateMenu];
curTrackIndex = trackPlayingIndex;
}
-
+
//Update Play/Pause menu item
if (playPauseMenuItem)
{