NSString *appPath = [[[[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]; // get to the waaay top. Goes through LoginItems, Library, Contents, Applications [[NSWorkspace sharedWorkspace] launchApplication:appPath]; //[[NSWorkspace sharedWorkspace] launchApplication:@"AutoStart.app"]; NSLog(@"AutoStartHelper: App path:%@",appPath); [NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0];
Objective-C if (!alreadyRunning) { NSString *path = [[NSBundle mainBundle] bundlePath], *contents = @"Contents/"; NSRange contentsRange = [path rangeOfString:contents options:NSBackwardsSearch]; NSString *mainAppPath = [[path substringToIndex:contentsRange.location + [contents length]] stringByAppendingString:@"MacOS/LaunchAtLoginApp"]; [[NSWorkspace sharedWorkspace] launchApplication:mainAppPath]; }