Has anyone a one-line to find unused images in an Xcode project? (Assuming all the files are referenced by name in code or the project files - no code generated file names.)
Only this script is working for me which is even handling the space in the filenames:
Updated to support swift files and cocoapod. By default it's excluding the Pods dir and check only the project files. To run to check the Pods folder as well, run with --pod attrbiute :
/.finunusedimages.sh --pod
Here is the actual script:
#!/bin/sh
#varables
baseCmd="find ."
attrs="-name '*.xib' -o -name '*.[mh]' -o -name '*.storyboard' -o -name '*.mm' -o -name '*.swift'"
excudePodFiles="-not \( -path */Pods/* -prune \)"
imgPathes="find . -iname '*.png' -print0"
#finalize commands
if [ "$1" != "--pod" ]; then
echo "Pod files excluded"
attrs="$excudePodFiles $attrs"
imgPathes="find . $excudePodFiles -iname '*.png' -print0"
fi
#select project files to check
projFiles=`eval "$baseCmd $attrs"`
echo "Looking for in files: $projFiles"
#check images
eval "$imgPathes" | while read -d $'\0' png
do
name=`basename -s .png "$png"`
name=`basename -s @2x $name`
name=`basename -s @3x $name`
if grep -qhs "$name" $projFiles; then
echo "(used - $png)"
else
echo "!!!UNUSED - $png"
fi
done