2012-04-06 80 views
4

有没有办法通过编程的方式在我的应用程序中打开Finder的“获取信息”窗口?如何打开文件/目录获取信息窗口?

Get Info Window

+2

只是要清楚:你要问切换到搜索和显示实际Info面板,或者是你想在你的应用中显示面板? – 2012-04-06 19:23:42

+0

我想在我的应用程序中显示面板 – Kira 2012-04-06 19:26:47

回答

1

使用一些AppleScript的,它是很容易的:

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

有没有一种方法可以让它不带applescript?)简单地说,我从来没有使用过applescript – Kira 2012-04-06 19:34:26

+0

这是否会显示面板内应用程序,因为OP想要?我不是AppleScript的人,但是这不只是调用Finder中的面板? – 2012-04-06 19:34:30

+0

@ConradShultz嗯我开始我的回答之前,原来的帖子上添加评论。而且,Kira,applescript很容易处理,做一些谷歌搜索,你应该能够找到如何在自己的应用程序中执行applescript。 – 2012-04-06 19:35:49

1

AFAIK没有API来获取信息面板中的应用内展示。 (我欢迎这方面的更正。)想到的最接近的是通过快速浏览API提供的preview panel

我认为您需要构建自己的所有信息都可以通过NSWorkspaceNSFileManager类获得。

+1

当然,我可以让我的窗户,但我不想“重新发明轮子”,如果这已经对我做了 – Kira 2012-04-06 19:39:30

+0

在这种情况下,我认为你可能不得不。我敢打赌,你并不孤单 - 也许可以考虑将你的结果发布到GitHub上? – 2012-04-06 19:42:05

6

还有一个简单的解决方案,你可以在苹果的“照片搜索”项目中看到。

以下是可用于根据示例显示单个文件的“获取信息”窗口的代码。

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

希望,这将帮助,并通知你,这将与沙箱应用程序在工作狮子和后来。

+0

您使用剪贴板来存储文件?但是当用户点击CMD V时,也会粘贴我们请求的“Get Info”文件? 如果是这样,在获取信息之后从文件夹中删除文件(也出于内存原因?) – 2012-11-19 19:07:03

+0

当然,在NSPerformService调用某些延迟之后,您可以根据需要从剪贴板中删除文件。 – AmitSri 2012-11-22 11:59:43

1

我用这个代码开口一个文件 “获取信息” 窗口

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

但是,有一些bug。如果我的文件路径包含一个空格,例如path = @“/ Users/alexanderyolkin/Downloads/DETest/Folder/LICENSE 2”,NSPerformService会打开两个窗口“Get Info” - 用于路径和相同文件,不包含空格或文件夹。

因此,解决方案使用的是 [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);

多数民众赞成在工作完美

相关问题