1

I'm writing a simple preference pane app that will not be on the MAS and does not need to be sandboxed.

I am trying to get access to their user/library directory, or at least find the path.

I can do it this way:

NSString *filePath = @"/Users/USERNAME/Library/";

if I know their USERNAME, which I don't know how to get? Or maybe there is a better way?

Kenneth
  • 1,035
  • 1
  • 12
  • 26
  • 1
    Consider just using NSUserDefaults if you can... [In the docs](https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/classes/nsuserdefaults_class/reference/reference.html) – ahruss Jul 30 '14 at 02:37
  • 1
    I want access to the library so I can modify pLists that are in that directory (specifically, user defaults for what application opens what). – Kenneth Jul 30 '14 at 02:40
  • 2
    possible duplicate of [Getting path to users Library folder in OS X](http://stackoverflow.com/questions/7993319/getting-path-to-users-library-folder-in-os-x) – ahruss Jul 30 '14 at 04:42

1 Answers1

1

You can get username by calling NSUserName() function.

UPD: Understand question in wrong way. Please, use this function

// Obtain the user's real home directory
// Normally the sandbox returns the app container's user home folder, not the real one
+ (NSString *)homeDirectory {
    struct passwd *pw = getpwuid(getuid());
    return [NSString stringWithUTF8String:pw->pw_dir];
}
dimazava
  • 370
  • 1
  • 14