#!/bin/sh # Defaults, each of which are overidable from the command line FORMAT="jpeg" SIZE="112x112" bail(){ if [ "$1" = "-1" ]; then echo "Please specify a valid .app to extract an icon from." exit -1 fi } ParseInput () { if [ $# -eq 0 ]; then echo "Usage: Anything contained in []'s are optional." echo "Usage: $0 -a .app [-s] [-f] " exit -1; fi while [ -n "$1" ] # Parse the command line do case $1 in -[Aa]) APP_NAME=$(echo $* | sed -e 's/-s.*$//' -e's/^-a //' -e 's/^[ \t]*//;s/[ \t]*$//' ); shift ;; -[Ss]) SIZE=$2; shift ;; -[Ff]) FORMAT=$2; shift ;; -*) echo "ERROR: Bad flag \"$1\"."; exit -1; ;; esac shift done if [ "x$APP_NAME" = "x" ]; then bail "-1" elif [ "$(echo "$APP_NAME" | sed -e 's/^.*\.//' -e 's/\/.*$//')" != "app" ]; then bail "-1" elif [ ! -d "$APP_NAME" ]; then bail "-1" fi } if [ "$FORMAT" = "jpeg" ]; then FORMATPROPER=$(echo "$FORMAT" | sed 's/e//') fi ParseInput $* icnsfile="$(ls "$APP_NAME"/Contents/Resources | grep .icns)" for i in $(echo "$icnsfile") do echo -e "Convert $i? (y or n): \c" read convert if [ "$convert" = "y" ]; then echo -e "Please specify an output filename (example icon.$FORMATPROPER): \c" read output echo "sips -Z $SIZE -s format $FORMAT \""$APP_NAME"/Contents/Resources/$i\" --out ~/Desktop/$output 2>&1 >> /dev/null" | sh else echo "$i - skipping" fi done