MacOS copy图标shell脚本

不会shell  同学做的...

可以看见在当前文件夹下创建了一个icons文件夹

最后还压缩了文件夹

#!/bin/bash

# readPlist [plist] [key]
function readPlist() {
    plist=$1
    key=$2

    value=`plutil -p "$plist" | grep $key | awk -F '=>' '{print $2}' | sed -e 's/\"//g'`
    echo $value
}

# copyAppIcon [app] [dir]
function copyAppIcon() {
    apath=$1
    iDir=$2
    appName="${apath##*/}"

    if [ -d "$apath" ]; then
        icon=`readPlist "$apath/Contents/Info.plist" "CFBundleIconFile"`
        if [ "${icon##*.}" != "icns" ]; then
            icon="$icon".icns
        fi

        cp "$apath/Contents/Resources/$icon" "$iDir/$appName.icns"
    fi
}

iconDir="icons"
mkdir $iconDir
mkdir $iconDir/Applications
mkdir $iconDir/UtilitiesÅ

for app in /Applications/*
do
    if [ "$app" != "/Applications/Utilities" ]; then
        copyAppIcon "$app" $iconDir/Applications
    fi
done

for app in /Applications/Utilities/*
do
    copyAppIcon "$app" $iconDir/Utilities
done

echo "[*] copy icons done"
zip -rq icons.zip $iconDir/*
echo "[*] compresses the folder done"
rm -r $iconDir
echo "[*] del icons folder done"

 

posted @ 2015-06-05 22:01  cart55free99  阅读(264)  评论(0编辑  收藏  举报