Skip to content

Instantly share code, notes, and snippets.

@lodestone
Last active April 3, 2016 06:02
Show Gist options
  • Save lodestone/fd84d6cfd68ab35bd9f5c7656e839727 to your computer and use it in GitHub Desktop.
Save lodestone/fd84d6cfd68ab35bd9f5c7656e839727 to your computer and use it in GitHub Desktop.
Ruby script to set custom icons in Mac OS X El Capitan

Set custom icons in Mac OS X El Capitan

Reset your custom icons for apps in El Capitan with this script. Especially useful for apps that update too frequently. (I’m looking at you: Transmission and Calibre)

Instructions:

  1. Put reset-custom-icons somewhere in your $PATH

  2. chmod +x WHEREVER_YOU_PUT_THE_SCRIPT

  3. Edit .config/custom-icons.yaml adding the app name and path of the icon on your computer.

All done!

Cheers!

# ~/.config/custom-icons.yaml
Applications:
-
app: Taskpaper
icon: /Users/z/Sync/Media/Icons/Taskpaper-Checkmark-Icon.png
-
app: Typora
icon: /Users/z/Sync/Media/Icons/Typora-Icon.png
# FileTypes:
# - type: pdf
# icon: /blah.png
#!/usr/bin/env ruby
require "yaml"
config_file = ENV['HOME'] + "/.config/custom-icons.yaml"
if File.exists?(config_file)
yaml = YAML.load_file(config_file)
else
File.open(config_file, "w"){|file| file << "Applications:\n -\n app: APPNAME\n icon: ICONPATH"}
%x[$EDITOR #{config_file}]
end
yaml["Applications"].each do |application|
app = "/Applications/#{application['app']}.app"
icon = application["icon"]
puts %x[rm -rf #{app}/Icon\r]
puts %x[sips -i #{icon} > /dev/null]
puts %x[DeRez -only icns #{icon} > /tmp/icns.rsrc]
puts %x[Rez -append /tmp/icns.rsrc -o #{app}/Icon\r]
puts %x[SetFile -a C #{app}]
puts %x[SetFile -a V #{app}/Icon\r]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment