Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa-在Finder中打开文件包_Cocoa - Fatal编程技术网

Cocoa-在Finder中打开文件包

Cocoa-在Finder中打开文件包,cocoa,Cocoa,我正试图打开某个包中的Finder 我得到了这个文件Example.backup,它只是一个带有扩展名的文件夹。在finder中,您可以右键单击它(显示包内容),我将看到文件。(没有目录文件夹) 我尝试过用NSWorkspace的方法打开它,但是没有人打开该目录下的查找器,他们要么选择文件,要么用相关程序打开它 也许在AppleScript中有这样做的方法吗?还是可可 谢谢因为还没有人回答,所以可能没有一行解决方案 我所能想到的只是一个解决方法:使用-R选项调用/usr/bin/open,这将在

我正试图打开某个包中的Finder

我得到了这个文件Example.backup,它只是一个带有扩展名的文件夹。在finder中,您可以右键单击它(显示包内容),我将看到文件。(没有目录文件夹)

我尝试过用NSWorkspace的方法打开它,但是没有人打开该目录下的查找器,他们要么选择文件,要么用相关程序打开它

也许在AppleScript中有这样做的方法吗?还是可可


谢谢

因为还没有人回答,所以可能没有一行解决方案

我所能想到的只是一个解决方法:使用-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];

NSWorkspace也这样做。遗憾的是,苹果公司没有考虑修改NSWorkspace来打开软件包。我也想做同样的事情,但这段代码对我不起作用。已选择.app文件的打开查找程序。您是否找到解决此问题的方法?在回答时,代码工作正常。如果您只是在命令行“/usr/bin/open-R/path/to/yourapp.app/yourfile”上尝试openfinder位,会发生什么情况?