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

需要用到PlistBuddy
PlistBuddy是Mac自帶的專門解析plist的小工具

1、拿到工程絕對路徑

#獲取plist文件所在路徑
project_path=$"/Users/~/~/~"
PlistPath=${project_path}/config.plist

2、PlistBuddy各命令

  • 獲取
#獲取整個(gè)plist
/usr/libexec/PlistBuddy -c "print" info.plist
#讀取某個(gè)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"

#獲取整個(gè)plist
/usr/libexec/PlistBuddy -c "print" info.plist
#讀取某個(gè)Key
/usr/libexec/PlistBuddy -c "Print : key" "$PlistPath"

# 將A.plist 合并到 B.plist中
/usr/libexec/PlistBuddy -c 'Merge A.plist'  B.plist

exit 0
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容