美文网首页iOS高级编程
Mac上利用sell脚本修改.plist文件

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

作者: 子疯zp | 来源:发表于2019-10-30 21:02 被阅读0次

需要用到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

相关文章

网友评论

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

    本文链接:https://www.haomeiwen.com/subject/wbpavctx.html