Created
July 4, 2025 16:19
-
-
Save BomberFish/0eb50650fe8bd49a02dcec9a213b0a41 to your computer and use it in GitHub Desktop.
Get the profile photo of an account on macOS. Works from within App Sandbox.
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
func profileImage(for username: String) -> NSImage? { | |
guard let local = try? ODNode(session: .default(), name: "/Local/Default"), | |
let record = try? local.record(withRecordType: kODRecordTypeUsers, name: username, attributes: nil), | |
let details = try? record.recordDetails(forAttributes: [kODAttributeTypePicture, kODAttributeTypeJPEGPhoto]) else { | |
return nil | |
} | |
if let jpeg = (details[kODAttributeTypeJPEGPhoto] as? [Data])?.first { | |
return NSImage(data: jpeg) | |
} else { | |
if let paths = (details[kODAttributeTypePicture] as? [String]) { | |
for path in paths { | |
if let img = NSImage(contentsOfFile: path) { | |
return img | |
} | |
} | |
} | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment