PlistBuddy学习笔记

PlistBuddy学习笔记

PlistBuddy是Mac自带的专门解析plist的小工具,由于PlistBuddy并不在Mac默认的Path里,所以需要使用绝对路径来引用这个工具。

数据类型:
string, array, dict, bool, real, integer, date, data

命令格式:
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

查看帮助

$/usr/libexec/PlistBuddy --help

打印plist文件

$/usr/libexec/PlistBuddy -c "print" info.plist

添加普通字段

$/usr/libexec/PlistBuddy -c 'Add :Version string 1.0' info.plist

添加数组;先添加key值,再添加value值。

$/usr/libexec/PlistBuddy -c 'Add :Application array' info.plist

$/usr/libexec/PlistBuddy -c 'Add :Application: string app1' info.plist
$/usr/libexec/PlistBuddy -c 'Add :Application: string app2' info.plist

添加字典;先添加key值,再添加value值。

$/usr/libexec/PlistBuddy -c 'Add :Person dict' info.plist

$/usr/libexec/PlistBuddy -c 'Add :Person:Name string yansu' info.plist
$/usr/libexec/PlistBuddy -c 'Add :Person:sex string boy' info.plist

打印字段相应的值

$/usr/libexec/PlistBuddy -c 'Print :Person' info.plist

在array中根据下标打印某个特定的值

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

推荐阅读更多精彩内容

  • Lua 5.1 参考手册 by Roberto Ierusalimschy, Luiz Henrique de F...
    苏黎九歌阅读 13,949评论 0 38
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,461评论 0 10
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,027评论 19 139
  • 飞入平湖白小仙,摇身美酒醉团圆。沾唇甜爽温凉液,落雪轻柔寒素天。 寻瑤器,送甘泉。千斤糯米贺春联。花灯旧巷旗袍影,...
    雨意生香阅读 1,196评论 80 83
  • 我们还是分手吧!或者,这句话你来说。 茉莉说出这句话的五秒钟后,我突然明白,原来,有些事情说不可能,就真的是不可能...
    十壹先生阅读 1,290评论 19 23