I've created an app that has a NSTableView which represents a series of files. From this, I want to be able to drag a row (i.e. a filename) from my NSTableView to Finder, and the file be created in that folder. However, the bit I can't work out is that I need to modify the contents of the original file, before it gets copied to Finder.
I've added the following line so I can drag outside of my NSTableView:
[self.tableView setDraggingSourceOperationMask:NSDragOperationCopy forLocal:NO];
And I can get it to copy the actual file, provided I add a current files location to the pasteboard, using:
- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard {
[pboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:nil];
NSMutableArray* dragfiles = [[NSMutableArray alloc] init];
NSString* file = [self.files objectAtIndex:row];
NSString* filepath = [[[self.pathControl URL] path] stringByAppendingPathComponent:file];
[dragfiles addObject:filepath];
[pboard setPropertyList:dragfiles forType: NSFilenamesPboardType];
[dragfiles release];
}
But, because I want to modify the contents of the file, I don't want to put filepaths onto the pasteboard. I've tried using NSFileWrapper, but Finder doesnt seem to accept this as a valid format.
I've checked Google, and I've found several suggestions that you can create a temporary file and use that filepath. But, this feels ugly.
Is it possible to send data to Finder? Is there a way to solve this?