iOS高级编程

Mac上利用sell脚本修改.plist文件

2019-10-30  本文已影响0人  子疯zp

需要用到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"
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
上一篇 下一篇

猜你喜欢

热点阅读