Objective c 如何打开文件/目录获取信息窗口?
有没有办法在我的应用程序中以编程方式打开Finder的“获取信息”窗口以获取路径Objective c 如何打开文件/目录获取信息窗口?,objective-c,macos,Objective C,Macos,有没有办法在我的应用程序中以编程方式打开Finder的“获取信息”窗口以获取路径 使用一些applescript,它非常简单: set macpath to POSIX file "/Users/rross/test.applescript" as alias tell application "Finder" to open information window of macpath AFAIK没有API来获取应用程序内显示的信息面板。(我欢迎对这一点的更正。)我想到的最贴切的东西是通过Qu
使用一些applescript,它非常简单:
set macpath to POSIX file "/Users/rross/test.applescript" as alias
tell application "Finder" to open information window of macpath
AFAIK没有API来获取应用程序内显示的信息面板。(我欢迎对这一点的更正。)我想到的最贴切的东西是通过Quick Look API提供的
我认为构建自己的应用程序所需的所有信息都可以通过和类获得。还有一个简单的解决方案,您可以在苹果的“照片搜索”项目中看到 下面是根据示例显示单个文件的“获取信息”窗口的代码
- (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和更高版本中的沙盒应用程序一起使用 我将此代码用于打开一个文件“获取信息”窗口 但是,有一些错误。如果我的文件路径包含一个空格,例如
path=@”/Users/alexanderyolkin/Downloads/DETest/Folder/LICENSE 2“
,则NSPerformService将打开两个窗口“获取信息”,用于路径和没有空格的同一文件或文件夹
因此,解决方案正在使用中
[pboard setPropertyList:fileList forType:NSFilenamesPboardType]代码>
代码是
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);
这是完美的只是想澄清一下:你是想切换到Finder并显示实际的信息面板,还是想在你的应用程序中显示所述面板?我想在我的应用程序中显示面板有没有办法不使用applescript进行显示?)简单地说,我从未使用过AppleScriptll,我想按照OP的要求在应用程序中显示面板?我不是一个AppleScript的人,但这不只是调用Finder中的面板吗?@ConradShultz-hmm我在原始帖子添加评论之前就开始回答了。还有,Kira,applescript很容易处理,做一些谷歌搜索,你应该能够找到如何在你自己的应用程序中执行applescript。谢谢你的回答,我会试试的,当然我可以做我的窗口,但我不想“重新发明轮子”,如果这件事已经对我做了,我想你可能不得不这么做。我敢打赌你并不孤单——也许考虑把你的结果寄给Github?你用剪贴板来存储文件吗?但是当用户点击CMD V时,它是否也会粘贴我们请求的文件“获取信息”?如果是这样的话,在获得信息后从粘贴板中删除文件不是很好吗(也是出于内存原因?)当然,在NSPerformService调用后,您可以根据需要延迟从剪贴板中删除文件。
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);