MacOS – Yet Another Custom Sidebar Icon Question (System Info.plist Question)

customizationfinderfoldersiconmacos

I have perused just about every Google search I could think of and have gotten what I think seems to be close to an answer on how to set custom icons in the sidebar WITHOUT having to resort to Dropbox's mach_inject hackery, but I have a few questions and I'm stumped. My main question is: Can you set a 'type' to a folder? The reason is ask is because when going into /System/Library/CoreServices/CoreTypes.bundle/Contents there is an Info.plist file. This file shows icon associations for system folders. Before delving into sidebar icons though, firstly, I'd like to know how the 'regular' icons are associated to the system folders. I'll use the 'Documents' folder as an example. I can see under Document Types in this Info.plist file, Item 155 is for the Documents folder, and it explains that the icon that should be associated to the Documents folder should be DocumentsFolderIcon.icns. It also indicates that the 'Document OS Type' is a 4-character type, named 'docs'.

docs type

Is it safe to assume that if I created a New Folder, I could somehow edit either an extended attribute or some sort of metadata that declares my new folder to be of type 'docs' which will cause Finder to display the DocumentsFolderIcon.icns for it? How can I modify my folder 'type' like that?

Furthermore, in the same Info.plist file, it explains the sidebar icons. The dictionary for Item 10 (the Documents sidebar icon) explains that the Document OS Type of 'sbDc' will display the SidebarDocumentsFolder.icns. Again, with my newly created folder, can I somehow edit an attribute or metadata to indicate that the sidebar type should be 'sbDc' instead of the default 'sbFd' (which is for the Generic Folder icon).

sbDc type

Being able to modify those attributes on my new folder in that way can provide me with a proof of concept to get custom sidebar icons without requiring mach_inject tricks, and allow me to be able to create new folders that act as if they were system generated folders with their own custom sidebar icons and everything.

(I know there is ANOTHER file in /Library/Preferences named com.apple.sidebarlists.plist, but I'm confused, because for the Documents folder definition, it indicates a decimal number for com.apple.LSSharedFileList.TemplateSystemSelector which, when converted to hex, then to ASCII, spell out 'sbDt' and NOT 'sbDc' which is listed in the system Info.plist file as Documents sidebar type ) –EDIT– Actually, I modified that in an attempt to make a change to see what happens; the decimal number that's originally set for Documents by default is in fact 1,935,819,875, which translates to 'sbDc' in ASCII. (The following screenshot has my change in it.)

number > hex > ASCII

So just to recap, how can I modify the attributes, metadata, or whatever it's called, on a newly created folder to declare it of type 'docs' instead of type 'fldr, fold, utif, or aexf' so that instead of the generic folder icon, it displays the Documents folder icon?

Again, I know this has been beaten to death, I just feel like I am so close to being able to set custom icons and sidebar icons without having to resort to code injections…

Thanks in advance!

–Just one extra note about 'regular' custom icons (not sidebar icons): I know how to set a custom icon for a folder using conventional methods, but when you select an image using preview and then 'Get Info' on your folder and paste your image in the upper left corner to set the icon, the size on disk for your folder changes…which is not how system folders have their icons set. System folders must be associating their icons by that 4-character type somehow and I'm trying to do the same with my own custom folder.–

UPDATE

Tobias' answer (see his answer below) seems to be on the right path, but I can't for the life of me find what file connects a path to an icon. I've tried searching every file on my computer for the string '/Sites' using Terminal. If you create a 'Sites' folder in your 'home' folder, it will get a special icon with a Safari logo on it, but if you create a 'Sites' folder on say, your Desktop, it will get a generic folder icon. So path discrimination is definitely going on, thanks Tobias! For some reason 'Sites' is special and leftover from older versions of OS X I believe or intended for web developers (although, curiously, it does not get a special Sidebar icon, it still gets a generic folder icon on the Sidebar). Could anyone explain how and why the Sites folder is so special? Emphasis on the how, lol.

Best Answer

If you are simply trying to change the default icon to something else, here is an answer I provided for a previous post. I have used this to customize several icons in the Finder's sidebar.