Created
August 6, 2016 13:13
-
-
Save gcbrueckmann/b7c48a3ef5525ef6c0af14b006c4d30f to your computer and use it in GitHub Desktop.
Determine the actual home directory URL from a sandboxed app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSURL { | |
/// A URL identifying the user's home directory, typically in `/Users`. | |
/// | |
/// Calling `NSHomeDirectory()` from a sandboxed app will return an descendant of the app sandbox. | |
/// This property on the other hand will return the actual home directory outside the sandbox. | |
/// Note that access restrictions still apply, e.g. testing access to the returned URL will normally fail. | |
static var actualHomeDirectoryURL: NSURL? { | |
let pw = getpwuid(getuid()) | |
return NSURL(fileURLWithFileSystemRepresentation: pw.memory.pw_dir, isDirectory: true, relativeToURL: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment