Search code examples
objective-cmacoscocoansopenpaneliphoto

How to access Media section (Photo & Movies) directly from NSOpenPanel in Mac OS X application?


I already refered this link

iMedia

Now i am using NSOpenPanel to open iPhoto library folder.

Here is the code which allow to open.

int i = 0;
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
[openDlg setCanChooseFiles:YES];
[openDlg setAllowedFileTypes:[NSArray arrayWithObjects:@"public.image",@"public.video",nil]];
[openDlg setAllowsMultipleSelection:TRUE];
[openDlg setAllowsOtherFileTypes:NO];

if ( [openDlg runModal] == NSOKButton )
{
    NSArray *files = [openDlg URLs];
    for( i = 0; i < [files count]; i++ )
    {
        NSLog(@"File path: %@", [[files objectAtIndex:i] path]);
    }
}

This code always open my Finder library folder, As i want to open Media Photo and Movies folder directly.

Please give me any solution.

I have attached here one screen shot.

enter image description here

Thanks & Regards,


Solution

  • You may consider adding the following code snipet:

        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSError *error = nil;
        NSURL *picturesURL = [fileManager URLForDirectory:NSPicturesDirectory inDomain:NSUserDomainMask appropriateForURL:NULL create:NO error:&error];
        NSURL *iPhotoURL = [picturesURL URLByAppendingPathComponent:@"iPhoto Library.photolibrary"];
    
        [openDlg setDirectoryURL:iPhotoURL];
    
        // Now run the dialog
    

    This won't help if the user has moved his iPhoto library to some non-standard location.