title: Changing mac folder icon with Ruby?
body: <p>Is it possible to change the icon of a Mac folder using a set of Ruby commands? I believe that OSX requires a .icon file to be present within the modified folder, perhaps there is a specific way of converting a jpg or png to the .icon criteria?</p>
  
  <p>-- Edit (Working solution. Requires ImageMagick and <a href="http://sourceforge.net/projects/osxutils/" rel="nofollow">OSXUtils</a>)
  * note, for my application I intended to set folder icons. It is entirely possible this could work for files as well.</p>
  
  <pre><code>def set_icon image, folder
  
          # Convert to absolute paths and setup
          image = File.expand_path image
          folder = File.expand_path folder
          dim = 512
          thumb = folder + '/'+ 'thumb.png' # PNG supports transparency
          icon = folder + '/'+ 'icon.icns'
  
          # Convert original to thumbnail
          system "convert '#{ image }' -quiet -thumbnail '#{dim}x#{dim}&gt;' \
            -background none -gravity center -extent #{dim}x#{dim} '#{ thumb }'"
  
          # Set icon format. Causes 'libpng warning: Ignoring attempt to set cHRM RGB triangle with zero area'
          system "sips -s format icns '#{ thumb }' --out '#{ icon }'"
  
          # Set the icon
          system "seticon -d '#{ icon }' '#{ folder }'"
  
          # Cleanup
          FileUtils.rm thumb
          FileUtils.rm icon
  end
  </code></pre>