Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open file/directory Get Info window?

Is there a way to open the Finder's "Get Info" window within my app for some path, programmatically?

Get Info Window

like image 214
Kira Avatar asked Apr 06 '12 19:04

Kira


1 Answers

There is another simple solution, you can see in the apple's "Photo Search" project.

Following is the code which you can use to show "Get Info" Window for single file as per the sample.

- (void)infoButtonAction:(NSOutlineView *)sender {
    // Access the row that was clicked on and open that image
    NSInteger row = [sender clickedRow];
    SearchItem *item = [resultsOutlineView itemAtRow:row];
    // Do a "reveal" in finder
    if ([item filePathURL]) {
        NSPasteboard *pboard = [NSPasteboard pasteboardWithUniqueName];
        [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
        [pboard setString:[[item filePathURL] path]  forType:NSStringPboardType];
        NSPerformService(@"Finder/Show Info", pboard);
    }
}

I have further modified the code as per my need to show the dialog for multiple files as follows:

NSPasteboard *pboard = [NSPasteboard pasteboardWithUniqueName];
[pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];

NSMutableArray *fileList = [NSMutableArray new];

//Add as many as file's path in the fileList array
for(FileItem *item in fileItems) {
    [fileList addObject:[[item.filePath filePathURL] path]];
}

[pboard setPropertyList:fileList forType:NSFilenamesPboardType];
NSPerformService(@"Finder/Show Info", pboard);

Hope, this will help, and FYI, this will work with sandboxed App in Lion and later.

like image 93
AmitSri Avatar answered Nov 17 '22 14:11

AmitSri