Question

How can I reveal a bundle contents in Mountain Lion using [NSWorkspace selectFile:nil inFileViewerRootedAtPath:pathEndingWithDotBundle]? I mean: pathEndingWithDotBundle is a path whose basename is something like "folder.bundle". If I call this method this way, the Terminal opens up and I don't know why...

Was it helpful?

Solution

It opens Terminal because it thinks you want to launch the bundle, and that's the default application. I would open a bugreport against this, because the documentation does not say that it will open the path. It says it that it will display it in a file viewer. It would be reasonable for this to be an error (since a bundle is not logically a directory; it's just phyiscally a directory). But it makes no sense for it to do something random like try to launch another program.

That said, it's fairly easy to work around. Just select the Contents folder, which is required to be within the bundle:

[[NSWorkspace sharedWorkspace] selectFile:[pathEndingWithDotBundle stringByAppendingPathComponent:@"Contents"] 
                 inFileViewerRootedAtPath:pathEndingWithDotBundle];

In 10.6+, you can use activateFileViewerSelectingURLs:

NSURL *URL = [NSURL fileURLWithPath:[pathEndingWithDotBundle stringByAppendingPathComponent:@"Contents"]];
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:@[URL]];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top