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"

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。