Skip to content

Instantly share code, notes, and snippets.

@BomberFish
Created July 4, 2025 16:19
Show Gist options
  • Save BomberFish/0eb50650fe8bd49a02dcec9a213b0a41 to your computer and use it in GitHub Desktop.
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.
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