5

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.

3

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.

  • 2
    Thanks Dave. The goal is to be able to insert new definitions for totally new and custom folders, ie., keep all the defaults there, and then add new icons for my own custom folders. I'm trying to understand exactly how those 'Document OS Types' operate with those 4-character strings. I'm thinking there must be some sort of metadata for each -actual- folder that can be modified. Just as a test, I'd like to create a new folder, somehow set it's 'type' to 'docs' and see that its icon displays the same one as the Documents folder. – Nick J Nov 22 '13 at 14:24
2

You assume, that there has to be a property on the file/folder for it's special icon treatment.

Using the Terminal and ls -l@e shows all extended attribute keys and the Access Control List (ACL) associated with the file/folder. The only thing special about the special folders is, that the ACL states 0: group:everyone deny delete. A copy with cp -a, which retains everything including extended attribute keys and the ACL, does not retain the special icon.

So there is no property on the file/folder.

Instead, Finder treats these folders differently all on it's own.

It does this simply by path discrimination. Use sudo mv to verify this.


Additional notes

  • Name localization is done by a .localized file inside the folder.
  • Custom icons result in an attribute

    com.apple.FinderInfo      32
    

    in the folder and the special file

    -rw-r--r--@  1 <user> <group> 0 <dd> <mmm> <yyyy> Icon?
        com.apple.FinderInfo         32 
        com.apple.ResourceFork   202364 
    

    inside the folder.


Next step: Search for something which connects paths to their Document OS Type. Hopefully it is an easily accessible .plist or something.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .