MacOS – How to Change USB Thumb icon using Terminal or Bash/other scripting language

bashcommand linemacosterminal

I'm looking for a method to change USB or External Drive Icon using bash or any other command line method. I know how to manually chnage them like this

I am using El Capitan

Best Answer

You need to copy the .icns file to the root folder of the volume. The new file needs to be named .VolumeIcon.icns. For example, if you are using a Bash shell, have the file vol_external.icns and destination /Volumes/MyStick, then below would be the command.

cp  vol_external.icns  /Volumes/MyStick/.VolumeIcon.icns

A word of warning: Once you assign an icon to a volume, changing this icon is very difficult. I feel there must be a bug somewhere in OS X. However, deleting the icon does seem to work.

To get a directory listing for this copied file, you may need to include the -a option in the ls command line. For example, the command

ls  /Volumes/MyStick

will not display the file .VolumeIcon.icns, but the command

ls  -a  /Volumes/MyStick

will show the file.

Note: Normally, files starting with a . do not appear in the Finder application.