I have other questions on SO about making a sandboxed app launch at login, that apparently have no solution: here and here
As you know, you have to create a helper application that will launch the main app and die.
All tutorials out there say to add this to the helper delegate:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Get the path for the main app bundle from the helper bundle path.
NSString *basePath = [[NSBundle mainBundle] bundlePath];
NSString *path = [basePath stringByDeletingLastPathComponent];
path = [path stringByDeletingLastPathComponent];
path = [path stringByDeletingLastPathComponent];
path = [path stringByDeletingLastPathComponent];
[[NSWorkspace sharedWorkspace] launchApplication:path];
[[NSApplication sharedApplication] terminate:self];
}
This code does exactly nothing because the main app is not launched (for the reasons you will see on my other questions) and as a bonus the helper is not killed.
I have tried to kill the helper using a variety of methods, like
[NSApp terminate:self];
and even this dramatic method
NSArray *runningApplications = [[NSWorkspace sharedWorkspace] runningApplications];
NSString *theName;
NSNumber *pid;
for ( NSDictionary *applInfo in runningApplications ) {
if ( (theName = [applInfo objectForKey:@"NSApplicationName"]) ) {
if ( (pid = [applInfo objectForKey:@"NSApplicationProcessIdentifier"]) ) {
//NSLog( @"Process %@ has pid:%@", theName, pid );
if( [theName isEqualToString:@"MyHelper"] ) {
kill( [pid intValue], SIGKILL );
}
}
}
}
Nothing kills the helper.
As another bonus, when I launch the main app manually and it sits on the menu bar, I have the option to choose QUIT
from the main app itself, so I can quit the app but the main app itself is not killable too, using the same programmatically methods.
What is going on?
I have followed @vadian instructions and it is not working. I have uploaded a proof of concept project to here. You will see that the helper loads but not the app.