How to obtain an app icon regardless of current icon style?

Hey Team,

Using NSWorkspace.icon(forFile:) and pointing to an app bundle, the system returns an NSImage with the icon of the app, but in the current style.

For example, if the user selected tinted icons in Appearance in System Settings, then any icon I receive back from the API will be tinted using the current accent color.

Is there a way to override this and get the original icon?

Thanks, Ari

Answered by Frameworks Engineer in 892453022

There is not currently a way to do this. Please file a feedback request for an API addition.

Have you tried inspecting the representations of the NSImage? Or using another API, like NSURL EffectiveIcon?

There is not currently a way to do this. Please file a feedback request for an API addition.

It's not identical to the way you'd get it from IconServices, but you can always try from the filesystem instead:

let url = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "MY.APP.BUNDLE")!
let img = (try? url.resourceValues(forKeys: [.effectiveIconKey]).effectiveIcon) as? NSImage
img?.representations //This is full, but tinted
let bnd = Bundle(url: url)!
let name = bnd.infoDictionary?["CFBundleIconFile"] as? String ?? bnd.infoDictionary?["CFBundleIconName"] as? String ?? ""
let img2 = bnd.image(forResource: name)
img2?.representations //This is smaller but original
How to obtain an app icon regardless of current icon style?
 
 
Q