How to change file icon based file’s extension (.txt, .cpp, .docx, etc)


Desired result:

All .py files show a nice Python icon, regardless of what default program they opened with. (Same for .cpp files, .txt files, etc)


How it currently works:

Files (ex: .py files) are associated with their default program (in my case, Sublime text editor). The program (Sublime) then gets to choose what icon to show. It is possible to manually edit the program's (Sublime's) code to change the icons.


(I have done this with Sublime)


Why this result is not enough:

I recently switched to the Atom text editor which broke all the icons I had setup in Sublime. In addition, I can't change the icons for Atom like I did in Sublime. The Atom editor's plist file and resources folder is not setup like Sublime. (It is still possible, but rather than renaming/replacing things, Atom actually requires additional code to be written/modified, and I don't have the skill/knowledge to just write the necessary code, and I cannot find any tutorial for learning how)

I (and I believe many others) would prefer that the file icon was set independently from what the default program is. (I mean an Excel file should look like an Excel file whether or not I open it with Microsoft Excel, Numbers, or Sublime)


Possible solution:

It might be possible to fix this with an opener-app. If an opener-app is made the default opener for all file extensions, it would be able to set the icon for all those extensions. Then when the opener-app opens a file (for example .py file) it could then open that file with another program (for example Sublime). This way the default program could be changed through the opener-app, (for example, changing the opener-app to have all .py files open the Atom Editor) but, because the opener-app is still technically the default, all the file-icons remain unchanged.



Does anyone know of an app that does this already?

(If you know of any resources on how to create an app like this, I'd be happy to use them to make the app myself, and post the answer here)

Best Answer

  • (note, this appears not to work as of MacOS Big Sur v11.1 )

    I was able to hack together an app that does this. I created a repo explaining it here

    You can download the app using the download button on this page

    You can change the icons for existing file types. The only code I had to write for it was the following applescript:

    on open this_item
        tell application "Visual Studio Code"
            open this_item
        end tell
    end open

    Setup For yourself

    Open script editor (a built-in Mac app)

    Choose File -> Open -> where ever you downloaded the app

    You will then be viewing the grand total of 5 lines of code I wrote. Change "Visual Studio Code" to whatever app you want to be your default.

    Save the file (command + s).

    Move the app to your applications folder.

    Find a file you want to change the icon of (lets say a text file). Click the file once (highlight it), press command + i, go to the open with section. Choose DefaultOpener from the list, then click change all.

    You will probably have to reboot and toggle the show icon preview button (found in Finder's View Options) a few times for the icons to refresh and get replaced.

    I have a few default icons already loaded up ( Text files, cpp files, bash/shell files, python, and about 7 others), but if you want to add your own:

    • Open your applications folder
    • Right click on DefaultOpener
    • Choose show package content
    • Then open the content folder
    • Then open the resources folder
    • Then replace whatever icon with your own icon! (Note your replacement icon will need to be a .icns file)
    • Restart and toggle the show icon preview button a few times
    • List item

    Edit: All of the sublime code referenced in an earlier answer has been fully removed from the app