我正在尝试打开某个包中的 Finder。
我得到了这个文件,Example.backup,它只是一个带有扩展名的文件夹。在查找器中,您可以右键单击它(显示包内容),我将看到这些文件。 (没有 Contents 文件夹)。
我尝试使用 NSWorkspace 的方法打开它,但没有一个在该目录中打开查找器,他们要么选择文件,要么使用关联的程序打开它。
也许有办法在 AppleScript 中做到这一点吗?还是 cocoa ?
谢谢
最佳答案
由于尚未有人回答,因此可能没有一行解决方案。
我能想到的只是一个解决方法:使用 -R 选项调用/usr/bin/open,这将在 Finder 中显示给定的文件。由于您想要显示包的内容,因此您必须显示其中的任何文件(而不是包本身)。
缺点:不适用于空包(但您可以只显示包),Finder 窗口也会显示最后一项的选择。
NSString *pathToBundle = @"/tmp/test.app";
NSFileManager *fm = [[[NSFileManager alloc] init] autorelease];
// get the last file/directory in the package
// TODO: error handling / empty package
NSString *lastItemInBundle = [[fm contentsOfDirectoryAtPath:pathToBundle error:NULL] lastObject];
// reveal this file in Finder, by using /usr/bin/open
// see -R option in the manpage
NSTask *open = [[[NSTask alloc] init] autorelease];
[open setLaunchPath:@"/usr/bin/open"];
[open setCurrentDirectoryPath:pathToBundle];
[open setArguments:[NSArray arrayWithObjects:@"-R", lastItemInBundle, nil]];
[open launch];
关于Cocoa - 在 Finder 中打开文件包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3981244/