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];
}
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.
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.
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.
Getting multiple filenames is easy: (While getting multiple URLs is not with 10.5)
NSFilenamesPboardType
performDragOperation:
do the following to get an array of file paths: NSPasteboard* pboard = [sender draggingPasteboard];
NSArray* filenames = [pboard propertyListForType:NSFilenamesPboardType];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With