修改xcode中plist的脚本

为了做些自动化打包的东西,思路想歪了整了份这样的脚本

执行文件名字,一般跟创建工程文件夹名字相同

EXECUTABLE_NAME="${EXECUTABLE_NAME}"
echo $EXECUTABLE_NAME > /Users/derkin/Desktop/test3/HelloWorld/test.txt
echo "testtte" > /Users/derkin/Desktop/test3/testtte.txt

工程目录路径

PROJECT_DIR="${PROJECT_DIR}"
EXECUTABLE_NAME="${EXECUTABLE_NAME}"

工程plist路径

project_infoplist_path="${PROJECT_DIR}/${EXECUTABLE_NAME}/Info.plist"
echo $project_infoplist_path > ${PROJECT_DIR}/${EXECUTABLE_NAME}/project_infoplist_path.txt
echo $project_infoplist_path > /Users/derkin/Desktop/test3/infoplist.txt

编译时间

buildTime=date +%Y-%m-%d'+'%H:%M
echo $buildTime > ${PROJECT_DIR}/${EXECUTABLE_NAME}/buildTime.txt
echo $buildTime > ${PROJECT_DIR}/buildTime.txt

修改的命令行

modifyCmdString="'""Set :buildTime"" "${buildTime}"'"
echo $modifyCmdString

destinationCmd="/usr/libexec/PlistBuddy -c "${modifyCmdString}" ${project_infoplist_path}"
echo "cmd :\n "${destinationCmd}

执行plistbuddy处理方法

a="/usr/libexec/PlistBuddy"
a2="-c"
b="'Set :buildTime ${buildTime}'"
c="${project_infoplist_path}"
eval ${a}" "${a2}" "${b}" "${c}

写这个脚本用了很多时间,因为中间遇到了shell脚本无法执行脚本字符串

最后只能找到一个eval的方式来解决

猜测之所以是这样是因为会出现字符串编码转换问题或则是shell脚本内部机制问题

参考的附录:如何知道xcode build过程中会产生哪些宏变量 http://blog.csdn.net/fly52035/article/details/45894763

你可能感兴趣的:(修改xcode中plist的脚本)