Changing icon of a mounted disk image

I want to modify the icon of my mounted disk image, the same way as FUSE for OS X.

My desktop screenshot, where my disk image is the left one (name is censored):

Dekstop

Changing the icon of the dmg is simple, but has no effect on the mounted drive.


The, e.g., osxfuse-2.8.2.dmg disk image file uses a hidden .icns file named .VolumeIcon.icns in the root of the volume and has the Custom Icon attribute set, probably using /usr/bin/SetFile. E.g.: SetFile -a C /Volumes/FUSE\ for\ OS\ X

You can also change the icon of the mounted disk image from its Info sheet. Place the wanted icon on the Clipboard then select the disk image on the Desktop and press Command-I then click the icon in the upper-left corner of the Info sheet and paste the wanted image there.


To add a custom icon to the mounted volume of your dmg file, you first have to convert it to a sparsebundle or at least to a r/w dmg:

hdiutil convert -format UDSB -o /path/to/output/image /path/to/source/image.dmg #the extension sparsebundle will be added to the output file automatically

Then double-click the sparsebundle to mount it as a volume.

Copy the custom icon. Then cmdI the mounted volume. Highlight the icon in the upper-left corner of the Info window and paste the icon (in the clipboard) with cmdV.

Unmount the volume and convert to its previous type.