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?
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.
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.
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.
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.
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 );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With