Reading URLResourceKey.customIconKey and URLResourceKey.thumbnailKey file attributes

I'm trying to read the

URLResourceKey.customIconKey
and
URLResourceKey.thumbnailKey
file attributes with a Swift 4 app; as you guess I have some issue because no
NSImage
will be returned.


Questions: Does the two above keys refers to the custom icon (i.e. the Adobe Acrobat documents icon) and the thumbnails of the png / jpeg files?


If it's not the case, what the two keys really refers to?


Apple documentation has a really short description and google gave no results about.


By the way, here is the code I'm working on.


// Get file informations
let requiredAttributes : Set = [URLResourceKey.nameKey, URLResourceKey.creationDateKey, URLResourceKey.contentModificationDateKey, URLResourceKey.fileSizeKey, URLResourceKey.isPackageKey, URLResourceKey.thumbnailKey, URLResourceKey.customIconKey]
do {
let properties = try localURL.resourceValues(forKeys: requiredAttributes)
metadata.name = properties[URLResourceKey.nameKey] as? String ?? ""


let customIcon = properties[URLResourceKey.customIconKey] as? NSImage ?? nil
if customIcon != nil {
let saveURL = URL(fileURLWithPath: "/Users/fpiraneo/Desktop/fileicon.png")
try customIcon!.savePNGRepresentationToURL(url: saveURL)
}


let customThumbnail = properties[URLResourceKey.thumbnailKey] as? NSImage ?? nil
if customThumbnail != nil {
let saveURL = URL(fileURLWithPath: "/Users/fpiraneo/Desktop/filethumbnail.png")

try customThumbnail!.savePNGRepresentationToURL(url: saveURL)
}
} catch {
let errorDescription = "Error reading file attributes: \(localURL.absoluteString)"
comLog.addError(errorDescription)
return
}


Thank you for your help.

Replies

Which version of OSX ?


Have a look here if not already done, it is said that those keys are not implemented…


https://stackoverflow.com/questions/55497492/macos-and-swift-4-reading-urlresourcekey-customiconkey-and-urlresourcekey-thumb

.customIconKey
simply isn’t implemented (r. 6508029). Depending on your needs, you may be able to use
.effectiveIconKey
, which does take into account any custom icon.

I wasn’t able to track down a definitive answer about

.thumbnailKey
, but I suspect that it is similarly unimplemented. If you file a bug about
.thumbnailKey
and then post the bug number, I may be able to find out more.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"