- Grabbing a Mac app's icon: advanced Bash usage - Brett Terpstra
- CodeSnippets: Searching with grep & Spotlight's kMDItemDisplayName
#!/bin/sh
appname=`echo "$*" | sed 's|\.app$||'`
apppath=`mdfind -onlyin /Applications/ -onlyin ~/Applications/ -onlyin /Developer/Applications/ -onlyin /System/Library/CoreServices/ "kMDItemKind=='Application'" | grep -i "/$appname.app\$"`
bundleicon=`defaults read "$apppath/Contents/Info" CFBundleIconFile | sed 's|.icns$||'`
cp "$apppath/Contents/Resources/$bundleicon.icns" ~/Desktop/"$appname".icns
tell application "Finder"
repeat with f in (get selection)
do shell script "apppath=" & quoted form of POSIX path of (f as text) & "; appname=`echo \"$apppath\" | sed 's|.app$||;s|.*/||'`; icns=`defaults read \"$apppath\"/Contents/info CFBundleIconFile | sed 's|.icns$||'`; cp \"$apppath/Contents/Resources/$icns.icns\" \"$HOME/Desktop/$appname.icns\""
end repeat
end tell
for f in *.icns; do sips -Z 128 -s format jpeg -s formatOptions 60 "$f" -o "${f%.*}.jpg"; done