Launching/quitting a process


I want iTunes to start when my app starts and want iTunes to quit when my application quits. Is it possible to do this (Window & OS X) ?


You’d probably have to launch a background process helper to monitor the active apps…and launch / quit your app that way

On the Mac at least you can use GetNextProcess, you could also use an appleevent that times out to detect if its running, but GetNextProcess will be more reliable.

ProcessSerialNumber PSN={0,kNoProcess};
	ProcessInfoRec info;
	Str31 processName;
	FSSpec processSpec;
	OSErr theErr;
	while ((theErr=GetNextProcess (&PSN))==noErr && (!(PSN.highLongOfPSN == 0 && PSN.lowLongOfPSN == kNoProcess)))
			FSRef location;
			OSStatus theStatus;
			NSString *longProcessName;
			// NSLog(@"%@",longProcessName);
			if ([longProcessName isEqualToString:@"iTunes"])
// Found iTunes


[size=150][EDIT] [/size] DOh! Sorry, on re-reading the original post, I see that you want to close iTunes when your app closes… I initially read it the other way round! My apologies… the following post will probably be of little use, but I’ll leave it here anyway…

This might help for windows…

I’ve not tested it for a couple of months, so it may need to be tweaked; it’s also perhaps more than you’re after.

It allows you to start an external process, recieve notification of when it finishes, but also recieve the any console output it generates.

It was designed as a means of launching a compiler, so it can be made to function as a custom automatable command line.


Well, Justin posted some code to execute some bits of AppleScript. I think I could manage using that one, because it also allowed me to expand/collapse the iTunes window and set its bounds.
Thanks for the Windows code. I’ll use CreateProcess()