有没有办法以编程方式在我的应用程序中为某些路径打开 Finder 的“获取信息”窗口?
最佳答案
还有一个简单的解决方案,你可以在苹果的“图片搜索”项目中看到。
以下代码可用于根据示例显示单个文件的“获取信息”窗口。
- (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/