title: Copy to pasteboard file paths and urls on Snow Leopard or above
body: <p>I want to copy file paths in clipboard so they can be copied in text editors as strings but I want them also available to Finder to copy files.</p>
  
  <p>I've written the code shown below compliant with Snow Leopard guidelines (eg use writeObjects when copy file urls)</p>
  
  <pre><code>NSString* path1 = @"/Users/dave/trash/mas.sh";
  NSString* path2 = @"/Users/dave/trash/books.xml";
  NSURL* url1 = [NSURL fileURLWithPath:path1 isDirectory:NO];
  NSURL* url2 = [NSURL fileURLWithPath:path2 isDirectory:NO];
  NSArray* paths = [NSArray arrayWithObjects:path1, path2, nil];
  
  NSString* pathPerLine = [paths componentsJoinedByString:@"\n"];
  // Put strings on top otherwise paster app receives the url (only the first)
  // Urls will be used by Finder for files operations (copy, move)
  NSArray* urls = [NSArray arrayWithObjects:pathPerLine, url1, url2, nil];
  NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
  [pasteboard clearContents];
  [pasteboard writeObjects:urls];
  </code></pre>
  
  <p>But on some editors (like XCode) also the urls are pasted as shown below (Finder uses correctly the urls to copy/move)</p>
  
  <pre><code>/Users/dave/trash/mas.sh
  /Users/dave/trash/books.xml
  file://localhost/Users/dave/trash/mas.sh
  file://localhost/Users/dave/trash/books.xml
  </code></pre>
  
  <p>How can I paste only the file paths without the file URLs using 10.6 compliant code?</p>
  
  <p>The <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSPasteboard_Class/Reference/Reference.html" rel="nofollow">NSFilenamesPboardType</a> usage <em>seems</em> discouraged</p>
  
  <blockquote>
    <p>NSFilenamesPboardType
        An array of NSString objects designating one or more filenames.
        On Mac OS X v10.6 and later, use writeObjects: to write file URLs to the pasteboard.
        Available in Mac OS X v10.0 and later.
        Declared in NSPasteboard.h.</p>
  </blockquote>