Reputation: 1485
We can right click an .app file and see its package contents. To open a file programmatically, we can use NSWorkspace but how to open the app's package contents?
I have searched a lot but seems there is no solution. Please help if I am missing something.
Upvotes: 0
Views: 805
Reputation: 22717
This seems to work:
NSString* contentsPath = [appPath stringByAppendingPathComponent:@"Contents"];
[[NSWorkspace sharedWorkspace] selectFile: contentsPath
inFileViewerRootedAtPath: appPath];
Upvotes: 1
Reputation: 112865
Per the comment it seems the OP want to open the contents directory of an app in the finder from code. The following line will accomplish that:
Swift:
let appName = "Safari";
let command:NSString = String(format:"open '/Applications/%@.app/Contents'", appName);
system(command.cStringUsingEncoding(NSUTF8StringEncoding))
Objective-C:
NSString *appName = @"Safari";
NSString *command = [NSString stringWithFormat:@"open '/Applications/%@.app/Contents'", appName];
system([command cStringUsingEncoding:NSUTF8StringEncoding]);
Alternate:
NSString *appPath = @"/Applications/Safari";
NSString *command = [NSString stringWithFormat:@"open '/%@.app/Contents'", appPath];
system([command cStringUsingEncoding:NSUTF8StringEncoding]);
Upvotes: 1
Reputation: 9392
An application is just a directory, show package contents just allows you to access the application as a directory rather than executing it. So you can access a file within an application such as
/Applications/Safari.app/Contents/Info.plist
Upvotes: 0