title: Files Copied to Clipboard are empty and "Missing Sandbox Extension" When Pasted
body: <p>I have an application that is copying files to the clipboard. Here is the relevant code (arguments is an array of NSStrings containing file paths):</p>
  
  <pre><code>NSMutableArray *filesToCopy = [[NSMutableArray alloc] init];        
  int i;
  for (i=1; i &lt; [arguments count]; i++) {
      NSString* pathToFile = [arguments objectAtIndex:i];
      NSURL* fileURL = [[NSURL alloc] initFileURLWithPath:pathToFile];
      [filesToCopy addObject:fileURL];
  }
  
  NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
  NSInteger changeCount = [pasteboard clearContents];
  BOOL OK = [pasteboard writeObjects:filesToCopy];
  </code></pre>
  
  <p>However, in testing when trying to paste a file copied to the clipboard by the program into an empty email in Mail, often the file shows up as zero bytes and the following error appears on the console:</p>
  
  <blockquote>
    <p>11/13/13 6:27:12.173 AM Mail[627]: Failed to obtain a valid sandbox extension for item: [789514] of flavor: [public.file-url] from the pasteboard.
    11/13/13 6:27:12.174 AM Mail[627]: Failed to get a sandbox extensions for itemIdentifier (789514).  The data for the sandbox extension was NULL</p>
  </blockquote>
  
  <p>and then that is followed by the following error on the console:</p>
  
  <blockquote>
    <p>11/13/13 8:24:41.947 AM sandboxd[172]: ([627]) Mail(627) deny file-read-xattr [full path of file]</p>
  </blockquote>
  
  <p>What is strange is that if I copy the file from Finder then it pastes just fine with no errors every time. In other words, somehow Finder copies the file to the clipboard with different information than the way I am doing it. To verify this, I did a simple AppleScript to return clipboard info. After I copy a file to the clipboard that returns the following:</p>
  
  <blockquote>
    <p>{{«class furl», 115}, {«class utf8», 115}, {«class ut16», 232}, {string, 115}, {Unicode text, 230}}</p>
  </blockquote>
  
  <p>After I copy the same file to the clipboard using Finder, the Applescript returns the following:</p>
  
  <blockquote>
    <p>{{«class furl», 33}, {«class icns», 795020}, {«class ut16», 112}, {«class utf8», 55}, {«class   8BPS», 1630436}, {«class BMP », 4194358}, {«class TPIC», 1059291}, {TIFF picture, 4197954}, {«class PNGf», 392648}, {«class jp2 », 213480}, {GIF picture, 121307}, {JPEG picture, 116181}, {Unicode text, 110}, {string, 55}}</p>
  </blockquote>
  
  <p>So Finder is putting more information about the file on the clipboard and different information. For example, the furl class has a different length. This extra information is obviously what is cause Mail to successfully past a file copied from Finder while it has an error pasting a file copied by my program.</p>
  
  <p>Any clues to what information I'm missing when I put the file on the clipboard or what extra information I should be adding to the paste? I'm guessing that Finder is pasting not just an array of NSURL's, but an array of Dictionary Keys that includes other file information. It also seems to be creating the furl class differently than I am. I've spent time pouring over documentation and I'm stuck on this one.</p>