user-44651
user-44651

Reputation: 4124

Unable to open Library folder via Objective-C

I'm trying to open a folder "~/Library/Application Support/Mozilla" in a Mac App using objective-c.

NSString *stringContaingPath = @"~/Library/Application Support/Mozilla";
NSURL *folderURL = [NSURL fileURLWithPath:stringContaingPath];
[[NSWorkspace sharedWorkspace] openURL: folderURL];

But each time I get the error

Error

When I go to open it.

Though the folder does exist.

enter image description here

Is there something special I need to do to open the folder? I'm not trying to write to it, just open it up for the user to see.

Upvotes: 0

Views: 105

Answers (1)

trojanfoe
trojanfoe

Reputation: 122381

The ~ symbol is only meaningful to the shell. You will have to expand it to /Users/username using NSHomeDirectory(); i.e.:

NSString *pathName = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Mozilla"];

However this will only work in a non-sandboxed app.

Upvotes: 1

Related Questions