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 [<Type>] - Clears out all existing entries, and creates root of Type
Print [<Entry>] - Prints value of Entry. Otherwise, prints file
Set <Entry> <Value> - Sets the value at Entry to Value
Add <Entry> <Type> [<Value>] - Adds Entry to the plist, with value Value
Copy <EntrySrc> <EntryDst> - Copies the EntrySrc property to EntryDst
Delete <Entry> - Deletes Entry from the plist
Merge <file.plist> [<Entry>] - Adds the contents of file.plist to Entry
Import <Entry> <file> - 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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,448评论 0 10
  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的阅读 13,551评论 5 6
  • 不知道从什么时候开始接触到这一理论:一个木桶装水的最大容量是由组成此桶的最短的一块木板的高度决定的,简称木桶理论。...
    杨文华阅读 610评论 0 0
  • 很多事情都是这样,你不去详细了解,就不会有感触,也不会心生一些想法,知道得越多,想法就越多。 杭州纵火案,本来只看...
    养猫人依若阅读 279评论 0 2
  • 有时候,没有下一次,没有机会重来,没有暂停继续。有时候,错过了现在,就永远永远的没机会了。 有时候,我们明明原谅了...
    梦mhon阅读 376评论 0 0