Categories
Blog

Change Your Icons On Yosemite With Scripting

I got tired of Yosemite’s icons and decided to take some initiative without the usual dependency on an app. It took about 2 days for me to perfect this strategy and now it’s time to make your process a lot easier than mine. πŸ”§

for all you machines out there

Intro

So maybe you got tired of Yosemite’s icons. That’s cool.

Even without apps like the once legendaryΒ CandyBarΒ orΒ LiteIcon, you can still change all your icons. No more dependencies!

I got tired of Yosemite’s icons and decided to take some initiative without the usual dependency on an app. It took about 2 days for me to perfect this strategy and now it’s time to make your process a lot easier than mine.

Tools

  • Terminal
  • your favorite set of icons
  • some patience

Step 1 – Get Your Icons

DeviantArtΒ is my go-to place for icons sets, but you can also tryΒ IconArchiveΒ for a broader range of options.

If you like the app icons I show in these pictures, then you’re welcome to download them from my Dropbox.

Here is aΒ ZIPΒ file of the icons and commands used in this tutorial.

A special thanks to these guys for the amazing circular icons that I use in this how-to.

Step 2 – Get The Command

I include this command file in theΒ ZIPΒ fileΒ mentioned inΒ Step 1, but for reference, here is the code for theΒ ChangeIcons.command.

#!/usr/bin/env ruby

require 'json' require 'shellwords'

if ENV['USER'] != 'root' puts "You'll be prompted once to enter you administrator password." end

Dir.chdir(File.dirname(__FILE__)) do

 file = File.read(%Q(.set_icons/icon_data.json)) icon_data = JSON.parse(file)

 icon_data.each do |key, value|

 app_path = "/Applications/#{key}"

 if Dir.exists?(app_path) and File.exists?("#{value}.icns") puts "Changing icon for #{app_path}" `sudo .set_icons/setfileicon "#{value}.icns" "#{app_path}"` end

 end

 puts "Restarting Finder and the Dock" # `killall Dock` # `killall Finder`

 puts %Q(Finished!)

end

Now here comes the tricky part. This command relies on aΒ JSONΒ file that is namedΒ icon-data.jsonΒ and aΒ UNIX Executable FileΒ calledΒ setfileicon.

These files are both included in a folder calledΒ set_iconΒ in theΒ ZIPΒ fileΒ provided inΒ Step 1.

TheΒ icon-data.jsonΒ file looks something like this:

{
  "1Password 5.app": "1Password 5",
  "Alfred 2.app": "Alfred 2",
  "Amphetamine.app": "Amphetamine"
}

 

It is formatted with the name of the app first in quotes followed by a semi-colon and then the name of theΒ icnsΒ file.

Edit thisΒ icon-data.jsonΒ file to include your own apps or create it yourself using your favorite text-editor.

Here is how theΒ JSONΒ file for the Utilities looks like.

It isΒ case-sensitive, so make sure to type everything correctly to suit what the app is called and what you named the correspondingΒ icnsΒ file.

When you are editing this file to add on your own apps, make sure there’s not a comma on the last line or there will be an error.

Now, usingΒ Terminal, type in the following:Β defaults write com.apple.finder AppleShowAllFiles YES. Once you pressΒ Enter, this command will show all the hidden files on your Mac. Don’t mess with any of these hidden files. The reason Apple hides them is so that the user has less of a chance of messing things up.

To make the files hidden again later, type in the same command but with a NO at the end like this:Β defaults write com.apple.finder AppleShowAllFiles NO.

After that, type inΒ killall FinderΒ into Terminal for the command to restart the Finder and have the hidden files be revealed in your Finder.

Show Hidden Files Command in Terminal

Now that you have your Finder revealing all the hidden files – in the folder where you have all your icons properly named, copy and paste the folderΒ set_iconsΒ from theΒ ZIPΒ fileΒ mentioned inΒ Step 1, and rename it toΒ .set_icons. Adding a period in front of the folder name makes it hidden and you will therefore not be able to see it anymore.

It looks exactly like theΒ .set_iconsΒ folder already included within the folder calledΒ UtilitiesΒ that can be found in theΒ ZIPΒ file.

Utility Sub-Folder

So if you want to change your Utility icons as well, theΒ .set_iconsΒ folder located in the sub-folderΒ UtilitiesΒ already has theΒ jsonΒ file with all the necessary modifications.

The only difference between theΒ ChangeIcons.commandΒ within theΒ All The IconsΒ folder and theΒ ChangeUtilityIcons.command located within theUtilities folderis that on Line 36, the app path is listed asapp_path = β€œ/Applications/Utilities/#{key}”`.

A special thanks toΒ James Moore, who created theΒ ChangeIcons.commandΒ to replace all the icons and Damien Bobillot who created theΒ setfileiconΒ UNIX Executable File.

Step 3 – Execute Command

otherwise known asΒ TLDR

Now you probably have something like the following:

  • a folder calledΒ All The IconsΒ with – all the icons you want to replace your old ones (inΒ icnsΒ format) – theΒ ChangeIcons.commandΒ that was included in thisΒ ZIPΒ fileΒ – aΒ hiddenΒ sub-folder calledΒ .set_iconsΒ with – a modifiedΒ icon-data.jsonΒ file to include your own personal apps – theΒ setfileiconΒ UNIX executable file

At this point, if you’ve done everything right, you can β€œhide” your hidden files again in your Finder by executing the commandΒ defaults write com.apple.finder AppleShowAllFiles NOΒ inΒ Terminal. Make sure to executeΒ killall FinderΒ as well so that your Finder restarts and shows the changes.

Now go ahead and click theΒ ChangeIcons.commandΒ to change all your icons simultaneously.

ChangeIcons.command in Terminal

You will be prompted to enter your password andΒ wallaΒ you have all your snazzy new icons in place in seconds!

If you want to change your Utility icons as well, go ahead and clickΒ ChangeUtilityIcons.commandΒ too within the sub-folder calledΒ Utilities, assuming you properly named all the icons so that it works with theΒ jsonΒ file that is shown inΒ Step 2.

Possible Errors You May Encounter

  • You tried to edit the command files and now have a syntax error, like in the form of quotes – just make sure to useΒ straight quotes. – You have a syntax error in yourΒ icon-data.jsonΒ file, like a comma on the last line. – You forgot to include a certain app in yourΒ icon-data.jsonΒ file and so the icon does not change when you execute the command. – An app is locked and, therefore, the icon cannot be changed. To unlock an app, go to the app, right click,Β Get Info. Uncheck theΒ LockedΒ button.

Locked App Error In Terminal

Locked App - Dropbox

Have fun with your new icons! 😍