PlistBuddy簡單使用,plistbuddy
PlistBuddy簡單使用
由於PlistBuddy並不在Mac預設的Path裡,所以我們得通過絕對路徑來引用這個工具:
/usr/libexec/PlistBuddy --help
下面我們來看看PlistBuddy的簡單使用列印:
初始化info.plist
/usr/libexec/PlistBuddy -c "print" info.plist
添加
/usr/libexec/PlistBuddy -c 'Add :Version string 1.0' info.plist
- 添加數組欄位,分兩步走,注意:
key之間用 : 隔開,且不能有空格
:
# 先添加key值/usr/libexec/PlistBuddy -c 'Add :Application array' info.plist# 添加value值yans67deMacBook-Pro:needfiles huangyg$ /usr/libexec/PlistBuddy -c 'Add :Application: string app1' info.plistyans67deMacBook-Pro:needfiles huangyg$ /usr/libexec/PlistBuddy -c 'Add :Application: string app2' info.plistyans67deMacBook-Pro:needfiles huangyg$ /usr/libexec/PlistBuddy -c 'Add :Application: string app3' info.plist
# 先添加key值/usr/libexec/PlistBuddy -c 'Add :Person dict' info.plist# 添加value值,/usr/libexec/PlistBuddy -c 'Add :Age string secret' info.plist/usr/libexec/PlistBuddy -c 'Add :Person:Name string yans67' info.plist/usr/libexec/PlistBuddy -c 'Add :Person:sex string boy' info.plist/usr/libexec/PlistBuddy -c 'Add :Person:weight string 65' info.plist
輸出
/usr/libexec/PlistBuddy -c 'Print :Person' info.plist
/usr/libexec/PlistBuddy -c 'Print :Application:2' info.plist
刪除
/usr/libexec/PlistBuddy -c 'Delete :Version' info.plist
修改
/usr/libexec/PlistBuddy -c 'Set :Application:1 string "thi is app1"' info.plist
合并
- 當有兩個plist檔案的時候,我們可以對其進行合併作業
# 將A.plist 合并到 B.plist中/usr/libexec/PlistBuddy -c 'Merge A.plist' B.plist
終端中會提示B.plist中有重複的索引值,所以預設跳過該索引值的合并
合并前
原文連結: http://www.jianshu.com/p/2167f755c47e
參考連結: http://shaojunxiao.com/2017/03/23/使用PlistBuddy修改info-plist檔案/?utm_source=tuicool&utm_medium=referral
https://segmentfault.com/a/1190000002423661