objective-c - 如何打开文件/目录获取信息窗口?

标签 objective-c macos

有没有办法以编程方式在我的应用程序中为某些路径打开 Finder 的“获取信息”窗口?

Get Info 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);
    }
}

我根据需要进一步修改了代码,以显示多个文件的对话框,如下所示:

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);

希望这会有所帮助,仅供引用,这将适用于 Lion 及更高版本中的沙盒应用程序。

关于objective-c - 如何打开文件/目录获取信息窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10048060/

相关文章:

cocoa - 处理 cocoa 中的菜单事件

ios - 自定义应用程序默认 NSDictionary

java - 向 Java 程序员解释 Objective-C 委托(delegate)

ios - 在 XMPPFramework 中发送消息

python - 为什么 format(str(var)) 给我的 os.system 属性错误

ios - 如何将缺少的库和框架正确添加到现有 Xcode 项目中

macos - 如何在 cocoa 的同一窗口中显示不同的 View ?

ios - 带 token 身份验证的 NSURLSession

objective-c - 带有实例变量的 NSString

android - 苹果机 : AVD wont launch