PlistBuddy

Plist文件是iOS项目中比较普遍的一种文件格式,类似于XML,都是通过键值对的形式存储数据,而PlistBuddy则是Mac自带的专门解析plist的友好工具。如果有自动化打包,动态修改iOS工程项目中的info.plist文件的需求,会用到PlistBuddy。
工具路径:
/usr/libexec/PlistBuddy
查看帮助:
/usr/libexec/PlistBuddy --help
PlistBuddy文档
$ /usr/libexec/PlistBuddy --help
Command Format:
Help - Prints this information
Exit - Exits the program, changes are not saved to the file
Save - Saves the current changes to the file
Revert - Reloads the last saved version of the file
Clear [] - Clears out all existing entries, and creates root of Type
Print [] - Prints value of Entry. Otherwise, prints file
Set - Sets the value at Entry to Value
Add [] - Adds Entry to the plist, with value Value
Copy - Copies the EntrySrc property to EntryDst
Delete - Deletes Entry from the plist
Merge [] - Adds the contents of file.plist to Entry
Import - Creates or sets Entry the contents of file

Entry Format:
Entries consist of property key names delimited by colons. Array items
are specified by a zero-based integer index. Examples:
:CFBundleShortVersionString
:CFBundleDocumentTypes:2:CFBundleTypeExtensions

Types:
string
array
dict
bool
real
integer
date
data

Examples:
Set :CFBundleIdentifier com.apple.plistbuddy
Sets the CFBundleIdentifier property to com.apple.plistbuddy
Add :CFBundleGetInfoString string "App version 1.0.1"
Adds the CFBundleGetInfoString property to the plist
Add :CFBundleDocumentTypes: dict
Adds a new item of type dict to the CFBundleDocumentTypes array
Add :CFBundleDocumentTypes:0 dict
Adds the new item to the beginning of the array
Delete :CFBundleDocumentTypes:0 dict
Deletes the FIRST item in the array
Delete :CFBundleDocumentTypes
Deletes the ENTIRE CFBundleDocumentTypes array
操作plist文件
打印
/usr/libexec/PlistBuddy -c "Print" info.plist

修改
/usr/libexec/PlistBuddy -c 'Set :Software:Gallery:Version "1.1"' ~/Desktop/com.sample.plist

添加
/usr/libexec/PlistBuddy -c 'Add :Software:Gallery:Version string "1.0"' ~/Desktop/com.sample.plist

删除
/usr/libexec/PlistBuddy -c 'Delete :Software:Gallery:Version' ~/Desktop/com.sample.plist

合并
/usr/libexec/PlistBuddy -c "Merge ~/Desktop/Global.plist :Software:Gallery" ~/Desktop/com.sample.plist

你可能感兴趣的:(PlistBuddy)