Created
April 18, 2012 16:21
-
-
Save bitsandbooks/2414689 to your computer and use it in GitHub Desktop.
Bash function to grab an app's icon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Lovingly ripped off from Brett Terpstra. | |
# http://brettterpstra.com/grabbing-a-mac-apps-icon-advanced-bash-usage-2/ | |
function geticon() { | |
APP=`echo $1|sed -e 's/\.app$//'` | |
APPDIR='' | |
for dir in "/Applications/" "/Applications/Utilities/" "/Developer/Applications/" "/Developer/Applications/Utilties/"; do | |
if [[ -d ${dir}$APP.app ]]; then | |
APPDIR=$dir | |
break | |
fi | |
done | |
if [[ $APPDIR == '' ]]; then | |
echo "App not found" | |
else | |
ICON=`defaults read "${APPDIR}$APP.app/Contents/Info" CFBundleIconFile|sed -e 's/\.icns$//'` | |
OUTFILE="$HOME/Desktop/${APP}_icon.jpg" | |
MAXAVAIL=`sips -g pixelWidth "${APPDIR}$APP.app/Contents/Resources/$ICON.icns"|tail -1|awk '{print $2}'` | |
echo -n "Enter max pixel width ($MAXAVAIL): " | |
read MAX | |
if [[ $MAX == '' || $MAX -gt $MAXAVAIL ]]; then | |
MAX=$MAXAVAIL | |
fi | |
/usr/bin/sips -s format jpeg --resampleHeightWidthMax $MAX "${APPDIR}$APP.app/Contents/Resources/$ICON.icns" --out "$OUTFILE" > /dev/null 2>&1 | |
echo "Wrote JPEG to $OUTFILE." | |
echo -n 'Open in Preview? (y/N): ' | |
read ANSWER | |
if [[ $ANSWER == 'y' ]]; then | |
open -a "Preview.app" "$OUTFILE" | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment