title: Launching executable with NSTask - Sandboxing problems?
body: <p>I have an Mac OSX application that launches a executable located in /Contents/Resources.
  The application is not intended to be released on App Store and so I don't have sandbox turned on.</p>
  
  <p>The launch code:</p>
  
  <pre><code>toolPath = [[[NSBundle mainBundle] pathForResource:@"myexecutable" ofType:@""] copy];
  task = [[NSTask alloc] init];
  [task setLaunchPath: toolPath];
  pipe = [[NSPipe alloc] init];
  [task setArguments:[NSArray arrayWithObjects:@"-someArg", someVariable, nil]];
  file = [[NSFileHandle alloc] initWithFileDescriptor:[pipe fileHandleForReading].fileDescriptor];
  [task setStandardOutput: stderrPipe];
  [task launch];
  </code></pre>
  
  <p>The thing is - this all works fine when running in Xcode.
  It also works fine when exporting the application to desktop and running it.</p>
  
  <p>However, if I zip the application, upload it to a webserver, and then download it on the same computer (or dropbox it to another Mac), the task no longer launches! I get no error in the system console or anything.</p>
  
  <p>I researched some on this problem and found that OSX will mark a new applicaton as "quarantined" special permission right. So I investigated the difference between the downloaded app and the exported app:</p>
  
  <p>Permissions on the executable after exporting my application from Xcode:</p>
  
  <pre><code>-rwxr-xr-x  1 Username  staff   65724 21 Jul 16:31 executableName
  </code></pre>
  
  <p>At this point the app works fine and the executable is launched from a button inside the app.</p>
  
  <p>And after zipping the application, uploaded to server, downloaded, unzipped, and opening the application and accepting the "This application was downloaded from internet" dialogue:</p>
  
  <pre><code>-rwxr-xr-x  1 Username  staff   65724 21 Jul 16:31 executableName
      com.apple.quarantine        26 
  </code></pre>
  
  <p>At this point nothing happens when I push the button in my app.</p>
  
  <p>If I then run <code>xattr -rd com.apple.quarantine</code> on the whole app, the quarantine notice is removed:</p>
  
  <pre><code>-rwxr-xr-x  1 Username  staff   65724 21 Jul 16:31 executableName
  </code></pre>
  
  <p>but the executable is <strong>still</strong> not being launched!</p>
  
  <p>At this point I now have the following permissions on my desktop app:</p>
  
  <p>/Contents/MacOS:</p>
  
  <pre><code>-rwxr-xr-x  1 Username  staff  407728 21 Jul 16:31 appName
  </code></pre>
  
  <p>/Contents/Resources:</p>
  
  <pre><code>-rwxr-xr-x  1 Username  staff   65724 21 Jul 16:31 executableName
  </code></pre>
  
  <p>And on the downloaded app which I used xattr -rd on:</p>
  
  <p>/Contents/MacOS:</p>
  
  <pre><code>-rwxr-xr-x  1 Username  staff  407728 21 Jul 16:31 appName
  </code></pre>
  
  <p>/Contents/Resources:</p>
  
  <pre><code>-rwxr-xr-x  1 Username  staff   65724 21 Jul 16:31 executableName
  </code></pre>
  
  <p>The first app works fine and the second one never launches the executable. What the heck is going on? It's the same app, on the same computer, with the same permissions, but the downloaded one just doesnt work.</p>
  
  <p>This problem appears across all OSX versions on different computers.</p>