To understand how Finder uses icons

Hello everyone. I cannot speak for everyone, of course, but it seems there are many people, not just me, who have or had the issue that Finder shows wrong icons. For example, you have Sublime Text installed, and you have test.md somewhere. But despite you have set “Open with” to “Xcode” for all your Markdown files (Get Info > Open with = Xcode > Change All), your test.md will have Sublime Text icon.

There are many solutions on the internet about this issue, for example, a long discussion here or this article by Howard Oakley.

However, in practice, when I tried to understand why some icons didn’t look the way I expected, all these solutions and explanations weren’t enough. So I decided to figure it out myself, with a lot of tests and so on.

I made some observations and I want everyone to help me check them, for our common benefit. So that if one have wrong icons, he or she can understand why it happen and what to do.

Part 1. Pre-requirements

  • Update macOS and install/update Sublime Text, CotEditor, Typora, and Xcode.

  • Start up your computer in macOS Recovery and disable system integrity protection (Options > Continue > Utilites > Terminal), then reboot.

    csrutil disable
    

    (Later you can enable it back the same way, using csrutil enable.)

    reboot
    
  • Write down the following script to clear the icon cache, you will use it a lot:

    sudo rm -rfv /Library/Caches/com.apple.iconservices.store; sudo find /private/var/folders/ \( -name com.apple.dock.iconcache -or -name com.apple.iconservices \) -exec rm -rfv {} \; ; sleep 3;sudo touch /Applications/* ; killall Dock; killall Finder
    
  • For convenience, disable “Show icon previews” in your test directory.

Part 2. My observations: Markdown

Create test.md > Get Info > Open With = Sublime Text > Clear the icon cache using the script above. The icon will be changed to

test.md > Get Info > Open With = CotEditor > Clear the icon cache using the script above. The icon will be changed to

test.md > Get Info > Open With = Typora > Clear the icon cache using the script above. The icon will be changed to

test.md > Get Info > Open With = TextEdit > Clear the icon cache using the script above. Note that the icon will be changed to the icon it would be if you changed “Open with” to “Xcode” instead of “TextEdit”! (I hope this sentence is clear, Englsh is not my primary language.) Here it is:

As far as I understand, this is because TextEdit doesn’t support Markdown, from the point of view of Finder, and so Finder use an icon from the most “nearest” app that do support it. Note that I don’t understand why Finder preferred Xcode over Sublime Text, CotEditor, or Typora, all of which do support Markdown as well.

Part 3. My observations: Lua

(The Lua case doesn’t tell us anything new. It simply confirms what is already written in the Markdown section.)

Create test.lua > Get Info > Open With = Sublime Text > Clear the icon cache using the script above. The icon will be changed to

Get Info > Open With = TextEdit or Xcode > Clear the icon cache using the script above. The icon will be changed to

As far as I understand, this is because neither TextEdit nor Xcode support Markdown, from the point of view of Finder, whereas Lua is supported by Sublime Text and CotEditor, and so Finder use an icon from the most “nearest” app that do support it, which happen to be CotEditor. Note that I don’t understand why Finder preferred CotEditor over Sublime Text.

My questions

  1. Does everything works the same for you?

  2. Do you know whether my explanations above are correct?

  3. Do you know why Finder preferred Xcode over Sublime Text, CotEditor, and Typora for Markdown; and why it preferred CotEditor over Sublime Text for Lua?

I can feel your concerns; icons have been a trouble for me too.

I have used your terminal entry, but I didn’t have to disable SIP to do it. What works for me is to boot into Safe Mode, let it sit for a bit, and then reboot back into normal mode. That resets many icons to what they’re supposed to be.

I think one of your problems might be that you have more than one program that understands a particular file type. Pages and Nisus Writer Pro, for instance, both understand RTF, but Nisus Writer Pro understands it natively and Pages doesn’t. I can’t get Nisus Writer Pro to pick the DOCX icon in its internal Resources folder for those files, it uses TXT instead. I’ve learned to live with it; they still open properly in NWP.

Interesting, thanks. How long does it take for you?

a few minutes on my M1 base model MacBook Pro for the whole process.

EDIT: my problem is having to do it more than once, as I keep trying out new combinations of apps. That I shouldn’t do. At least Agenda is holding out as my notes app; nothing else even comes close.

5 minutes, doesn’t work for me. MacBook Pro, M1 Pro chip, 16 GB RAM

That’s surprising. I wonder why. Safe Mode clears out many caches.

I asked the same question on Ask Different, and there is an answer from a guy who seems to really understand these things, but I cannot figure out what I should to do according to him:

Apparently (before my time with Macs) there used to be an indicator (in the “Resource Fork”?) that associated a document file with the application that was supposed to open it. Then Apple “went Windows” and started using the file extension to determine the application. All I know now is that if you do a Get Info on a document you can assign the application you want to open it with and then click on Change All… to have all files with the same name extension open with that app. You can drag a file with the icon you want to the icon in the Get Info window to change the icon. I don’t know if Change All will propagate it.

In practice, I tend to leave all of this alone since it never seems to work reliably. I also use Onyx to clean up all those caches.

before my time with Macs

Tom, I see you are a Mac user from 2006. Do you rememeber whether this issue is from Steve’s Jobs era?

I think the changeover was started with the NeXT-based OS X. Both schemes were supported, with obvious potential for conflicts, about the time I started with 10.3. So yeah, it was in Steve Job’s second era.

The best explanation I have found of why this mess is going on is on Reddit:

When you install an app, it may assert itself as the default handler for certain file types, changing their icons. Then if you install another app and it doesn’t assert itself with fresh icons, the defaults linger. Its kinda a mess. Also, if the developer didn’t include icons for all sizes in the installer, you may see different icons in different views. Also a mess.

(I have edited a quote to make it easy to understand without reading the Reddit thread itself.)

https://www.reddit.com/r/applehelp/comments/2w3h8q

1 Like