Mac中启动另一个程序并将窗口置于最前面 发表于 2012-03-16 | 分类于 pieces 在Mac的开发中,我们可能需要在自己的程序中启动另一个程序,并让该启动的程序窗口置于最前面,这一段代码便可以做到。 12345678910111213141516- (void)launchSoftWithBundleID:(NSString *)softPath{ NSBundle *softBundle = [NSBundle bundleWithPath:softPath]; NSString *bundleID = [softBundle bundleIdentifier]; //运行程序 NSTask *softTask = [[NSTask alloc] init]; [softTask setLaunchPath:softPath]; [softTask launch]; //得到运行的程序,并置于最前面 NSArray *array = [NSRunningApplication runningApplicationsWithBundleIdentifier:bundleID]; if ([array count] > 0) { NSRunningApplication *runningApp = [array objectAtIndex:0]; [runningApp activateWithOptions:NSApplicationActivateIgnoringOtherApps]; }}