Since macOS High Sierra sips --addIcon is no longer supported.
An easier way to add and image to a file/folder is to use fileicon npm package.
The new syntax is:
fileicon set foo img.pngThe old method setIcon is kept here a an archive:
Take an image and make the image its own icon:
sips -i icon.pngExtract the icon to its own resource file:
DeRez -only icns icon.png > tmpicns.rsrcAppend this resource to the file you want to icon-ize.
Rez -append tmpicns.rsrc -o file.extUse the resource to set the icon.
SetFile -a C file.extAppend a resource to the folder you want to icon-ize.
Rez -append tmpicns.rsrc -o $'myfolder/Icon\r'Use the resource to set the icon.
SetFile -a C myfolder/Hide the Icon\r file from Finder.
SetFile -a V $'myfolder/Icon\r'rm tmpicns.rsrc
Source: Stackexchange
Could you explain this code in more detail? It seems to me like this code sets a custom icon for a file/folder. Is this correct?