Warm tip: This article is reproduced from stackoverflow.com, please click
drag-and-drop macos cocoa finder nspasteboard

How do I handle multiple file drag/drop from Finder in Mac OS X 10.5?

发布于 2020-03-27 15:39:56

I need to get the URLs of all files dragged/dropped into my application from Finder.

I have a Cocoa app running on 10.6 which does this by using the new 10.6 NSPasteboard APIs which handle multiple items on the pasteboard. I'm trying to backport this app to 10.5. How do I handle this on 10.5?

If I do something like below, I only get the first URL:

    NSArray *pasteTypes = [NSArray arrayWithObjects: NSURLPboardType, nil];
    NSString *bestType = [pboard availableTypeFromArray:pasteTypes]; 
    if (bestType != nil) {
        NSURL *url = [NSURL URLFromPasteboard:pboard];
    }        
Questioner
robottobor
Viewed
66
catsby 2010-01-04 22:00

The IKImageKit programming topics outline a way to do this like so (paraphrased):

   NSData *data = [pasteboard dataForType:NSFilenamesPboardType];
   NSArray *filenames = [NSPropertyListSerialization
        propertyListFromData:data
            mutabilityOption:kCFPropertyListImmutable
                      format:nil
            errorDescription:&errorDescription];

See here: Image Kit Programming Guide: Supporting Drag and Drop