Skip to content

Instantly share code, notes, and snippets.

@vibrazy
Created January 23, 2012 10:50
Show Gist options
  • Save vibrazy/1662452 to your computer and use it in GitHub Desktop.
Save vibrazy/1662452 to your computer and use it in GitHub Desktop.
How to find unused images in an XCode project?
#!/bin/sh
# -------
# Usage sh unusedImages.sh (jpg|png|gif)
# -------
# Caveat
# 1 -
# NSString *imageName = [NSString stringWithFormat:@"image_%d.png", 1];
# This script would incorrectly list these images as unreferenced. For example, you might have
# This script will incorrectly think image_1.png is unreferenced.
# 2 - If you have a method, or variable with the same name as the image it won't pick it up
PROJ=`find . -name '*.xib' -o -name '*.[mh]' -o -name '*.storyboard' -o -name '*.plist'`
for imageName in `find . -name '*.'$1`
do
name=`basename -s .$1 $imageName`
name=`basename -s @2x $name`
name=`basename -s ~ipad $name`
name=`basename -s @iPad $name`
if ! grep -q $name $PROJ; then
echo "$imageName"
fi
done
@benchester
Copy link

love it

@fly2never
Copy link

how about the path include a space in it?

@gogfried
Copy link

Pretty much useless when you have a space somewhere in your directory structure.

@vinayak-codigami
Copy link

Getting no such file and directory multiple times. Not working for me. Any alternate solution?

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