Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Possible Duplicate:
Changing a file or folder icon using the Terminal

This is a continuation of this thread from Super User. The question is how to set an icon on a directory. At first I was trying cp -R, which did copy the directory with the icon, but it also copied every file and subdirectory in the folder. Then Keith Thompson suggested that one of the invisible files inside a directory might be responsible for the icon (because cp -R would preserve those/bring them with the copy) so I tried copying the 'Icon?' invisible file from a folder with the desired icon to new directory (newly created with mkdir) but that didn't work. He said to ask here, because this is more geared towards Mac- and UNIX-based questions. In that last post, he also suggested the .DS_STORE file (which I've seen, but I think stores which files to display) but I may try copying that into a new folder too...

  1. Empty directory is created
  2. No invisible files
  3. Regular files are put into the folder, '.DS_STORE' appears.
  4. Icon is set manually on the folder, the 'Icon?' file appears.

Does anyone know how to set an icon on a directory through the shell?

share|improve this question
add comment

marked as duplicate by mankoff, bmike Aug 14 '12 at 18:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

You can create a shell script and name it something like mkdir_WithIconFrom

#!/bin/sh
mkdir $1
cp $2/Icon\r $1
SetFile -a C $1

This will create a directory at the first path you specify on the command line with the icon from the existing directory whose path you specify second on the command line, assuming the target directory has a custom icon.

share|improve this answer
1  
Yes, setfile is the correct way to do this. –  Adam Davis Mar 20 '12 at 20:43
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.