Skip to content

Instantly share code, notes, and snippets.

@joshavant
Last active January 30, 2016 18:36
Show Gist options
  • Save joshavant/e3ef26fc14953125a748 to your computer and use it in GitHub Desktop.
Save joshavant/e3ef26fc14953125a748 to your computer and use it in GitHub Desktop.
How to manage custom OS X color palettes in your Xcode project

How to manage custom OS X color palettes in your Xcode project

The following steps configure your Xcode project to check the status of your custom color palette in the system, during the build process.

When your custom color palette is not installed in the system, Xcode's build process will fail with an error, instructing you to run a script which will install the file.

When the installed color palette doesn't match what is in your project's root directory (according to an md5 file checksum comparison), Xcode's build process will warn you to update the .clr file.

This system allows you to keep your custom color palette file in your project directory, under source control. Whenever changes to the palette file are pushed to the repo, Xcode will notice them and notify you during the build process.

  1. Place your custom .clr color palette file in the root of your project directory

  2. Create install_colors.sh in your project root:

    cp YOUR_COLOR_FILE_NAME.clr ~/Library/Colors
    

    (don't forget to chmod +x install_colors.sh)

  3. Create a new Xcode project Run Script with the following script contents (replacing YOUR_COLOR_FILE_NAME in line 1 with the filename you used in Step 2):

    COLOR_FILENAME="YOUR_COLOR_FILE_NAME.clr"
    
    #####
    
    SYSTEM_COLOR_FILE_PATH=~/Library/Colors/$COLOR_FILENAME
    
    if [ ! -f "$SYSTEM_COLOR_FILE_PATH" ]; then
        echo "error: Custom color palette not found in system! Run ./install_colors.sh"
        exit 1
    fi
    
    PROJECT_COLOR_FILE_MD5="$(md5 -q $COLOR_FILENAME)"
    SYSTEM_COLOR_FILE_MD5="$(md5 -q $SYSTEM_COLOR_FILE_PATH)"
    
    if [ ! "$PROJECT_COLOR_FILE_MD5" == "$SYSTEM_COLOR_FILE_MD5" ]; then
        echo "warning: Your system's custom color palette file does not match file in project directory! Run ./install_colors.sh to update."
    	exit 0
    fi
    
  4. There is no Step 4!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment