Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can a sandboxed Mac app save files?

My Mac app is sandboxed and I need to save a file. Where do I save this file? I can't seem to find the specific place where this is allowed without using an open panel. This is how I do it on iOS:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = [paths objectAtIndex:0]; 

What is the equivalent for the sandboxed directory on Mac?

like image 970
Jack Humphries Avatar asked Aug 03 '12 22:08

Jack Humphries


People also ask

Where are Mac app files stored?

It's inside the apps themselves. The apps are really just folders that looks like program files. If you right click on an app you press "Show Contents" and it will open the app as a folder where you are free to search for whatever files you want.

What is Sandbox folder Mac?

Overview. The App Sandbox is an access control technology that macOS provides and enforces at the kernel level. The sandbox's primary function is to contain damage to the system and the user's data if the user executes a compromised app.


1 Answers

That code snippet works on the Mac regardless of whether your application is sandboxed.

In a non-sandboxed Mac app, path will refer to the Documents folder in your home: e.g. /Users/username/Documents.

In a sandboxed app, it refers to a folder within the app sandbox: e.g. /Users/username/Library/Containers/com.yourcompany.YourApp/Documents

See the docs for details.

like image 88
rickster Avatar answered Nov 11 '22 14:11

rickster