简体   繁体   English

如何打开文件/目录 Get Info window?

[英]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?有没有办法以编程方式在我的应用程序中打开 Finder 的“获取信息”window 以获得某些路径?

获取信息窗口

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.以下代码可用于根据示例显示单个文件的“获取信息”Window。

- (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.希望,这会有所帮助,仅供参考,这将适用于 Lion 及更高版本的沙盒应用程序。

I used this code for openings one file "Get Info" window我使用此代码打开一个文件“获取信息”window

NSPasteboard *pboard = [NSPasteboard pasteboardWithUniqueName];
[pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
NSString *path = [selectedDuplicateItem getFileItemPath];
[pboard setString:path forType:NSStringPboardType];
NSPerformService(@"Finder/Show Info", pboard);

but, there is some bug.但是,有一些错误。 If my file path contains a space, for example path = @"/Users/alexanderyolkin/Downloads/DETest/Folder/LICENSE 2" , NSPerformService opens two windows "Get Info" - for path and for the same file without space or for folder.如果我的文件路径包含空格,例如path = @"/Users/alexanderyolkin/Downloads/DETest/Folder/LICENSE 2" ,NSPerformService 打开两个 windows “获取信息” - 用于路径和没有空格的同一文件或用于文件夹.

So, the solution was in using [pboard setPropertyList:fileList forType:NSFilenamesPboardType];因此,解决方案是使用[pboard setPropertyList:fileList forType:NSFilenamesPboardType];

and the code is代码是

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

NSString *path = [selectedDuplicateItem getFileItemPath];
NSMutableArray *fileList = [NSMutableArray new];
[fileList insertObject:path atIndex:0];

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

thats work perfect那是完美的工作

Use some applescript and it's quite easy:使用一些 applescript 很简单:

set macpath to POSIX file "/Users/rross/test.applescript" as alias
tell application "Finder" to open information window of macpath

AFAIK there is no API to obtain an info panel for in-app display.据我所知,没有 API 可以获取用于应用内显示的信息面板。 (I welcome correction on this point.) The closest thing that comes to mind is the preview panel available through the Quick Look APIs. (我欢迎在这一点上进行更正。)最能想到的是通过 Quick Look API 提供的预览面板

I think that all the information you would need to construct your own can be obtained via the NSWorkspace and NSFileManager classes.我认为您构建自己的文件所需的所有信息都可以通过NSWorkspaceNSFileManager类获得。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM