title: NSWorkspace launchApplication: fails for the first time with root user
body: <p>I am trying to launch one of my apps(say app2) from another of my apps(say app1) on my Mac OS X <strong>10.7.4</strong>. I am using the below code for the same:</p>
  <pre><code>[ [ NSWorkspace sharedWorkspace ] launchApplicationAtURL:[NSURL fileURLWithPath:appPath] options:NSWorkspaceLaunchDefault configuration:[NSDictionary dictionaryWithObject:[NSArray arrayWithObject: @&quot;mode&quot;] forKey:NSWorkspaceLaunchConfigurationArguments] error:&amp;err];
  </code></pre>
  <p>This works fine except for the first time i.e. if we have a new machine, then the first attempt for launching the app2 from app1 fails when tried for the first time when logged in as root user but works fine subsequently.</p>
  <p>Below is the error I get on dumping the NSError:</p>
  <blockquote>
  <p>2012-11-05 07:47:48 +0000: The application “App2” could not be launched because a miscellaneous error occurred (OSStatus -10810).</p>
  </blockquote>
  <p>Also, I get the below messages in &quot;<strong>All Messages</strong>&quot; in Console:</p>
  <blockquote>
  <p>11/4/12 11:47:48.329 PM com.apple.launchd[1]: System: Bug: 12B19: launchd + 79534 [AEF41441-17BC-36E6-B1F8-57BADBDFEBCF]: 0x0</p>
  <p>11/4/12 11:47:48.329 PM com.apple.launchd[1]: System: This API can only be used by a process running within an Aqua session.</p>
  <p>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</p>
  </blockquote>
  <p>The strange think is that it only fails for the first attempt with root user.</p>