Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting path to users Library folder in OS X

I need to open a NSSavePanel with the users Library folder as destination folder. Normally I would do this by entering ~/Library/ in [NSSavePanel beginSheetForDirectory].

This works fine as long as the application is not sandboxed. For sandboxed applications this will result in the NSSavePanel trying to access a folder inside the applications document "box".

I cannot refer to /Users/username/Library/ as I do not know the users username at runtime. So how do I link to this path in cocoa?

like image 287
Øystein Avatar asked Nov 03 '11 10:11

Øystein


People also ask

How do I find the user Library folder on a Mac?

In the Finder, hold down the Option key when using the Go menu. Library will appear below the current user's home directory. Note: After you open the Library folder, you can drag the Library icon from the top of that window to the Dock, sidebar, or toolbar to make it readily accessible.

How do I find folder path in OSX?

Show the path to a file or folder On your Mac, click the Finder icon in the Dock to open a Finder window. Choose View > Show Path Bar, or press the Option key to show the path bar momentarily. The location and nested folders that contain your file or folder are displayed near the bottom of the Finder window.

What is the Library folder on Mac OS X?

In macOS, the library folder is used to store user account settings, preference files, app support files, caches, and other important data that allows your Mac to function as it should. Making haphazard changes to the library folder can cause damage to your system, which is why Apple hides the folder by default.

How do I find Library folder on Mac terminal?

Access the Library folder directly through the Terminal:Click the Spotlight Search icon in the upper right corner. Enter "Terminal" In the Terminal window, enter "open library". The library opens in a Finder window.


1 Answers

I'm not sure how sandboxing fits in with this, but you can find the user's library directory using:

NSArray* paths = NSSearchPathForDirectoriesInDomains( NSLibraryDirectory, NSUserDomainMask, YES );
like image 154
JWWalker Avatar answered Sep 27 '22 20:09

JWWalker