+- (void)applicationLaunched:(NSNotification *)note
+{
+ NSDictionary *info = [note userInfo];
+
+ if ([[info objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"]) {
+ iTunesPSN.highLongOfPSN = [[info objectForKey:@"NSApplicationProcessSerialNumberHigh"] longValue];
+ iTunesPSN.lowLongOfPSN = [[info objectForKey:@"NSApplicationProcessSerialNumberLow"] longValue];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"ITMTRemoteAppDidLaunchNotification" object:nil];
+ }
+}
+
+- (void)applicationTerminated:(NSNotification *)note
+{
+ NSDictionary *info = [note userInfo];
+
+ if ([[info objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"]) {
+ iTunesPSN.highLongOfPSN = kNoProcess;
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"ITMTRemoteAppDidTerminateNotification" object:nil];
+ }
+}
+
+//This is just temporary
+- (NSString *)runScriptAndReturnResult:(NSString *)script
+{
+ AEDesc scriptDesc, resultDesc;
+ Size length;
+ NSString *result;
+ Ptr buffer;
+
+ script = [NSString stringWithFormat:@"tell application \"iTunes\"\n%@\nend tell", script];
+
+ AECreateDesc(typeChar, [script cString], [script cStringLength],
+&scriptDesc);
+
+ OSADoScript(asComponent, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
+
+ length = AEGetDescDataSize(&resultDesc);
+ buffer = malloc(length);
+
+ AEGetDescData(&resultDesc, buffer, length);
+ AEDisposeDesc(&scriptDesc);
+ AEDisposeDesc(&resultDesc);
+ result = [NSString stringWithCString:buffer length:length];
+ if ( (! [result isEqualToString:@""]) &&
+ ([result characterAtIndex:0] == '\"') &&
+ ([result characterAtIndex:[result length] - 1] == '\"') ) {
+ result = [result substringWithRange:NSMakeRange(1, [result length] - 2)];
+ }
+ free(buffer);
+ buffer = nil;
+ return result;
+}
+