Create ICNS Automatically by Batch

Just now when I open my documents folders, I was deeply mixed up by their icons.

Basically, text is also a kind of visual image. However, people need to decode, prefixly comprehend their meaning, and then recieve those signals. Relatively, normal iamge is much faster to be read than text.

And that’s why I usually clicked into the wrong directory. So I decided to change the icons of those folders.

One of the benefits under OS X is that users can just drag image into the folder’s info dialog and then its icon would be changed. But I’d like this process to be more “formally“. In other words, I want to convert images to be .icns types and then use them.

There had been many apps in Mac App Store achieving the function. But hundreds of reasons are suitable for me to reject using them, such as price, size, security and so forth. Frankly speaking, I want to build a bash script by myself.

Principle

  • First it scan the working directory and put available image names into file list. The reason I do not use variable is because filenames containing spaces would cause problem.
  • Loop each by each, call system commands sips and qlmanage to handle image process.
  • Call iconutil to create ICNS files.
  • Remove caches.

Usage

  1. Download it.
  2. Collect the images you want to covert and put them together with this script file in the same directory.
  3. Give it executable permission by enter chmod +x buildICNS.sh in terminal.
  4. In terminal, enter ./buildICNS.sh. Enjoy!

PS

  • This script will NOT hurt your original image files.
  • Actually I was going to push this post earlier, but I found that the formal script could be extended. For example support .svg and .pdf, support file name containing spaces. So I studied the shell language for some basic skills for accomplishing these functions. My mum was thinking I am mad. I am not!!! Just I enjoy learning and coding.

References(those pages helps me a lot!!)

License

MIT

0%