Skip to content

This tutorial will teach you how to change the default folder icon into your own custom folder icon using Terminal in macOS.

Notifications You must be signed in to change notification settings

ila-w/mac_folder_tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 

Repository files navigation

How to Change a Folder's Icon using Terminal

By: Ila Wallace - Difficulty: Medium - Time Required: 45 minutes


Introduction

This tutorial will teach you how to change the default folder icon into your own custom folder icon using Terminal in Mac OSX.

After the completion of this tutorial, you will be able to navigate through the Mac OSX directory in Terminal and assign your own custom .png image as a folder icon.


Requirements

To complete this tutorial, you will need access to a Mac OSX computer with at least 5 GB of available memory space. You must also have a basic understanding of how to use a Mac OSX computer and how to back up files.

Additionally, you will need to have Xcode command line tools installed. If you do not already have it installed, the section Installing Xcode Command Line helps guide you through the installation process.

Lastly, you will need to create a target folder and download a custom icon picked out in the form of a .png file placed inside. If you do not have an image file, you may choose from one of the default options provided in the section Downloading a Custom Icon.


Warning: If you have any important files on your desktop, make sure to back up these files in a separate location like on a flash drive or in OneDrive before proceeding any further. Using a UNIX Terminal can change your computer's file system and its data.



Introduction to Terminal

Table of Terminal Commands

This table lists all terminal commands used within this tutorial and states briefly what they do.

Terminal Commands Description
xcode-select --install Installs Xcode command line tools
xcode-select -v Prints the current version of installed Xcode command line tools
sips -i icon.png Formats image .png file to icon .png file
DeRez -only icns icon.png > tmpicns.rsrc Converts .png file to .icns file referenced through the tmpicns.rsrc file
Rez -a tmpicns.rsrc -o Icon$'\r' Generates Icon? file from .icns reference file
SetFile -a C . Sets Icon? file as the folder's custom icon
SetFile -a V Icon$'\r' Hides the Icon? file inside the folder
rm tmpicns.rsrc icon.png Removes unecessary leftover files
rm Icon$'\r' Deletes the custom icon from the folder

Getting Started

The downloads required for this tutorial are Xcode command line tools and at least one .png image file. Additionally, you will need to create a new folder on your desktop and place the image file inside.

Creating a New Folder

If you know how to create a new folder, rename your folder as custom and place your custom image into the folder. Then, skip to Navigating Directories.

Note: For the purposes of this tutorial, we will name and refer to the new folder as custom, but you can give the folder your own personalized name.


To create a new folder, you must do the following:

  1. Navigate to your desktop home screen

  2. Move your cursor to a preferred location and then press two fingers down on the track pad, or if you have an external mouse, right click on the folder to select it

  3. Click on the option New Folder

You should now see a blue default folder icon appear on your desktop.


To rename the folder, you must do the following:

  1. Place your cursor over the folder and then select the new folder by either pressing two fingers down on the track pad or right click on the folder to select it

  2. Click on the option Rename

  3. Type custom and then hit Return↩︎

Your folder should now be named custom.


Lastly, select the image file with your cursor and then drag it into the custom folder.


Checkpoint: The custom image should now be inside the custom folder.


Downloading a Custom Icon

In order to change the default folder icon, we need to have a new icon file to change it to.

If you have a custom icon downloaded to your computer, move a copy of the image to the icon to your desktop and name it icon.png.

If you do not have a custom .png file on hand, you can download an icon from here. Make sure to name it icon.png and save it to your desktop.


Checkpoint: The custom image icon.png should now be saved on your desktop.


Opening a New Terminal Window

To open the Terminal application, you must do the following:

  1. Press both the Command ⌘ and Space bar keys on your keyboard at the same time to open Spotlight Search

  2. Type the following text into the Spotlight Search prompt:

    Terminal
  3. Press Return↩︎ on your keyboard.


Checkpoint: A new Terminal window should be open and visible on your screen.


Installing Xcode Command Line Tools

To install Xcode command line tools, you must do the following:

  1. Open a new Terminal window

  2. Type the following text into the prompt:

    xcode-select --install
  3. When the pop up appears asking you if you would like to install the tools, click on the option Install.

  4. When the pop up appears stating the software was installed, click on the Done option.


If you would like to confirm your download, you can do the following:

  1. Open a new Terminal window

  2. Type the following text into the prompt and then press Return↩︎:

    xcode-select -v

The resulting output prints your Xcode tools current installed version to the console.


Checkpoint: The Xcode command line tools should be installed on your computer.


Navigating a Directory

When using Terminal for any task, it is important to have a basic understanding of where our current location in the Mac OSX directory file system and how to move through the directory file system.

If you know how to navigate a directory file system in Terminal, you may skip to Generating Icons.


Identifying the Current Location

To identify our current location in the directory tree, we can use pwd.

Type the following text into the terminal prompt and then hit Return↩︎:

pwd

The output printed to the console is shown below, where username is the name of your computer's current user.

  $ Users/username

Note: If the output printed to the console does not match the output format, type the following and then hit Return↩︎:

cd ~; pwd

The figure below is an asbtract representation of our current location. Congrats, you are now in your computer's home directory!

Users/
└── username/

Checkpoint: The current location should be inside the username folder directory.


Changing the Current Location

Now that we know where we are, we need to move to where we need to go.

Note: For the purpose of this tutorial, we will be working in your Desktop directory. If you would like to learn more about how to move through other directories, please see [insert link here].


To change our current directory to the Desktop, we can use cd.

Type the following text into the terminal prompt and then hit Return↩︎:

cd Desktop/custom/

If you would like to confirm you are in the Desktop directory, type the following text into the terminal prompt and then hit Return↩︎:

pwd

Output:

$ /Users/username/Desktop/custom

The figure below is an abstraction of our current location. We are now in the custom folder directory.

Users/
└── username/
    └── Desktop/
        └── custom/
            ├── icon.png

Checkpoint: The current location should be inside the custom folder directory.


Changing a Folder's Default Icon

Generating a Custom Icon for a Folder

Now that we are in the right location, we can now start converting icon.png into a usable icon for the custom folder.

To convert the image file, you must do the following:

  1. Type the following text into the terminal prompt and then hit Return↩︎:

    sips -i icon.png

    This command prepares the format of the png file for its transformation into an .icns file.

  2. Type the following text into the terminal prompt and then hit Return↩︎:

    DeRez -only icns icon.png > tmpicns.rsrc

    This command transforms the .png file into an .icns file and points to the newly converted file using the tmpicns.rsrc file.

  3. Type the following text into the terminal prompt and then hit Return↩︎:

    Rez -a tmpicns.rsrc -o Icon$'\r'

    This command generates the finalized icon file Icon? as a usable folder icon.


Checkpoint: The custom image file Icon? should be generated inside the custom folder.


Attaching a Custom Icon to a Folder

With the correct icon file generated, we can now attach it to the folder itself so it can be displayed.

To attach the icon and set it visible, type the following text into the terminal prompt and then hit Return↩︎:

SetFile -a C .

Checkpoint: The custom image file Icon? should now be visible as the custom folder's new icon.


Hiding a Custom Icon in a Folder

To avoid accidental deletion of the Icon? file, it is best to hide the file from normal view. In addition, removing the icon.png and tmpicns.rsrc files helps keep your newly customized folder tidy.

To hide the Icon? file, type the following text into the terminal prompt and then hit Return↩︎:

SetFile -a V Icon$'\r'

To remove unnecessary files, type the following text into the terminal prompt and then hit Return↩︎:

rm tmpicns.rsrc icon.png

Checkpoint: The custom image file Icon? should now be invisible in the custom. The files tmpicns.rsrc and icon.png should also be gone from the folder.


Removing a Custom Icon from a Folder

If at any point you wish to remove the custom icon, you can do so by removing the hidden Icon? file.

To remove the icon, type the following text into the terminal prompt and then hit Return↩︎:

rm Icon$'\r'

With the file now removed, your folder icon should return to its default icon.


Wrap Up

In this tutorial, you have learned how to:

  1. Open Terminal
  2. Change to the new folder's directory location
  3. Generate the icon file
  4. Attach the icon to the folder
  5. Hide the icon file
  6. Remove unecessary files
  7. Remove the custom icon from the folder

Further Reading

About

This tutorial will teach you how to change the default folder icon into your own custom folder icon using Terminal in macOS.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages