Custom icon file attribute

In the following, NSURLCustomIconKey is still broken on Catalina and will always return missing value.

set {theResult, theImage, theError} to (anURL's getResourceValue:(reference) forKey:(current application's NSURLCustomIconKey) |error|:(reference))

Is there another way to know if a Finder item has a custom icon?
Maybe using Carbon framework?
Or any shell script?

You could try using xattr and com.apple.ResourceFork.

Hi Shane,

xattr seems to be problematic with some files like compiled scripts. It always returns an error saying the file does not exists. (Maybe because it has a resource fork containing unexpected contents?)

I thought about another way to deal with this problem: compare the current icon to the default icon.

use framework "Foundation"
use framework "AppKit"
use scripting additions

set thePath to "/SomeFilePath"
set theURL to current application's NSURL's fileURLWithPath:thePath
set {hasResult, theUTI} to (theURL's getResourceValue:(reference) forKey:"NSURLTypeIdentifierKey" |error|:(missing value))
set theWorkspace to current application's NSWorkspace's sharedWorkspace()
set defaultIcon to (theWorkspace's iconForFileType:theUTI)'s TIFFRepresentation()
set thisIcon to (theWorkspace's iconForFile:thePath)'s TIFFRepresentation()

return (defaultIcon's isEqualToData:thisIcon)

Do you have some comment on this?

If it’s not too slow, go for it.

It’s veeeeeeeery slow. But it does the job.

:slight_smile: