I'd like Finder to display a particular icon for files based purely on its filename, not its extension. For instance, for a web project I have a Makefile sitting amidst PHP files, which all display the Atom logo:

The file already opens with Atom when double-clicked, even though TextEdit is technically my system's default text editor (which I never use, because Atom rules).

Is it possible to automatically assign an icon to makefiles system-wide, without manually copy+pasting an icon into it through the properties pane? Preferably without installing any third-party software, as this is really a cosmetic thing that's not worth having system bloat over.

I'm hoping there's some defaults-related thing I could tweak, or an entry in a plist file somewhere.


Setting Atom icon via command line for Makefile

There is no direct way to set icons based on filename only, but one can set them via command line and then apply to all makefiles on the Mac.

Here are the steps to set Atom's icon to a specific Makefile via command line (assuming you Developer Tools are installed).

  1. Get the Atom icon file from /Applications/Atom.app/Contents/Resources/file.icns
  2. Convert the image to icon
    sips -i file.icns
  3. Extract the icon to its own resource file  /Library/Developer/CommandLineTools/usr/bin/DeRez -only icns file.icns > tmpicns.rsrc
  4. Append this resource to the file you want to icon-ize /Library/Developer/CommandLineTools/usr/bin/Rez -append tmpicns.rsrc -o Makefile
  5. Use the resource to set the icon
    /Library/Developer/CommandLineTools/usr/bin/SetFile -a C Makefile
  6. Restart your Mac

you can run mdfind -name makefile to get all the makefiles in your system and write a script to do the above on them.

enter image description here

  • Thanks! Although I'm guessing there's no way to apply the icon to all future Makefiles as well...? (I'm tipping the answer is "no", but that wouldn't surprise me).
    – user154867
    Nov 2 '15 at 9:44
  • Also, what does step #2 do? Isn't the icns format already an icon file?
    – user154867
    Nov 2 '15 at 9:47
  • in this case it is. But I have added that step so that you can convert other files to icons using this command, if required.
    – sdayal
    Nov 2 '15 at 9:50

You must log in to answer this question.