macoscocoasandboxnssavepanelappstore-sandbox

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?


Solution

  • Not sure if this will work on a sandboxed application but this is how I do it right now. This will return /User/TheirUserName

    -(NSString *)homeDirectory
    {
        return NSHomeDirectory();
    }