Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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];
    }        
like image 514
robottobor Avatar asked Jan 04 '10 08:01

robottobor


People also ask

How do you control drag on a Mac?

On your Mac, select an item you want to drag—such as an image or block of text. Press and hold the trackpad or mouse while you drag the item to a new location. To copy the item instead of moving it, press and hold the Option key while you drag. Release the trackpad or mouse to drop the item in the new location.

How do you drag and drop multiple files on a Mac?

Option 2: Click and drag Just pull it over the files you want, and they will automatically be selected. From here, you can click on the group and then drag and drop it into a different folder or mass-delete them.

Why is it so hard to drag and drop on Mac?

A Mac's drag and drop function not working can be due to incorrect settings or an out-of-date operating system, software, or firmware. Mouse and trackpad preferences can also often confuse as there are several options users can select to customize how an item is selected and moved via Mac's mouse cursor.


1 Answers

Getting multiple filenames is easy: (While getting multiple URLs is not with 10.5)

  1. Register your view for NSFilenamesPboardType
  2. In performDragOperation: do the following to get an array of file paths:

NSPasteboard* pboard = [sender draggingPasteboard];
NSArray* filenames = [pboard propertyListForType:NSFilenamesPboardType];
like image 187
Thomas Zoechling Avatar answered Oct 20 '22 12:10

Thomas Zoechling