Problem Description:
I used Swift code to change a folder icon by calling the NSWorkspace.shared.setIcon(_:forFile:options:) method. The specific code is as follows:
NSWorkspace.shared.setIcon(coloredIcon, forFile: folderURL.path, options: [.exclude10_4ElementsIconCreationOption])
I noticed that the folder icon has been correctly changed in the Finder preview window, but the icon displayed on the desktop is still the original one.
Expected Result:
I hope the folder icon on the desktop can also be updated to display the new icon.
Solutions Tried:
I have tried restarting Finder and manually refreshing the icon cache, but the folder icon on the desktop still does not update.
Help Needed:
I would like to know if there is a way to automatically refresh the desktop folder icon cache in Swift code to ensure that the changed icon can be immediately displayed.