需要用到PlistBuddy
PlistBuddy是Mac自带的专门解析plist的小工具
1、拿到工程绝对路径
#获取plist文件所在路径
project_path=$"/Users/~/~/~"
PlistPath=${project_path}/config.plist
2、PlistBuddy各命令
- 获取
#获取整个plist
/usr/libexec/PlistBuddy -c "print" info.plist
#读取某个Key
/usr/libexec/PlistBuddy -c "Print : key" "$PlistPath"
- 添加key
Number=$"123"
#添加
/usr/libexec/PlistBuddy -c "Add :APP_ID: $Number" "$PlistPath"
#添加制定类型
/usr/libexec/PlistBuddy -c "Add :APP_ID: String $Number" "$PlistPath"
- 修改
#修改
/usr/libexec/PlistBuddy -c "Set :APP_KEY $Number" "$PlistPath"
- 删除
#删除
/usr/libexec/PlistBuddy -c "Delete :APP_ID" "$PlistPath"
- 合并
# 将A.plist 合并到 B.plist中
/usr/libexec/PlistBuddy -c 'Merge A.plist' B.plist
sell脚本
#!/bin/bash
Targets_Name="test"
#工程绝对路径
project_path=$"/Users/~/Desktop/test/test"
#plist文件所在路径
PlistPath=${project_path}/PushConfig.plist
Number=$"123"
#添加
/usr/libexec/PlistBuddy -c "Add :APP_ID: $Number" "$PlistPath"
#添加制定类型
/usr/libexec/PlistBuddy -c "Add :APP_ID: String $Number" "$PlistPath"
#修改
/usr/libexec/PlistBuddy -c "Set :APP_KEY $Number" "$PlistPath"
#删除
/usr/libexec/PlistBuddy -c "Delete :APP_ID" "$PlistPath"
#获取整个plist
/usr/libexec/PlistBuddy -c "print" info.plist
#读取某个Key
/usr/libexec/PlistBuddy -c "Print : key" "$PlistPath"
# 将A.plist 合并到 B.plist中
/usr/libexec/PlistBuddy -c 'Merge A.plist' B.plist
exit 0