NSWorkspace launchApplication: crash on first run as root

I am trying to run one of my applications (say app2) from another application (e.g. app1) on my Mac OS X 10.7.4 . I am using the code below for this:

[ [ NSWorkspace sharedWorkspace ] launchApplicationAtURL:[NSURL fileURLWithPath:appPath] options:NSWorkspaceLaunchDefault configuration:[NSDictionary dictionaryWithObject:[NSArray arrayWithObject: @"mode"] forKey:NSWorkspaceLaunchConfigurationArguments] error:&err];

This works fine except for the first time, i.e. if we have a new computer, then the first attempt to launch application2 from application 1 will fail if it is tried for the first time when you are logged in as root, but then stop working.

The following is the error that I get when resetting NSError:

2012-11-05 07:47:48 +0000: the "App2" application cannot be started due to various errors (OSStatus -10810).

In addition, I receive the following messages in the " All Messages " section of the console:

11/4/12 11: 47: 48.329 PM com.apple.launchd [1]: System: error: 12B19: launchd + 79534 [AEF41441-17BC-36E6-B1F8-57BADBDFEBCF]: 0x0

11/4/12 11: 47: 48.329 PM com.apple.launchd [1]: System: This API can only be used by a process running in an Aqua session.

11/4/12 11: 47: 48.329 PM App1 [2405]: spawn_via_launchd () failed, errno = 5 label = [0x0-0x57057] .com.ak.app1 path = / var / root / Library / Caches / com .ak.app2 / app2.app / Contents / MacOS / app2 flags = 0

It is strange to think that it only fails for the first attempt with the root user.

+2
source share
1 answer

, - . , LSOpenApplication , , UI, Lion. ,

+1

Source: https://habr.com/ru/post/1540905/


All Articles