用PlistBuddy修改Plist文件
Plist文件是以.plist为结尾的文件的总称. 众所周知, Plist在Mac OSX系统中起着举足轻重的作用,就如同Windows里面的Registry一样,系统和程序使用Plist文件来存储自己的安装/配置/属性等信息。正如可以使用命令行命令来处理大多数系统管理一样,操作Plist文件也是系统提供的。
所幸有PlistBuddy工具,这个工具通过它的简单语法就可以操作嵌套的键值。如果你的系统没有PlistBudy可以安装苹果的开发工具。
基本的使用可以查看man文档或者是在线帮助:
$ plistbuddy -h
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
这里主要解释一下PlistBuddy的几个关键点.
如何定义嵌套的键值: 正如前面说的它使用一种简单的描述方式,上一层的键值在前面,而每个键值之间使用":"符号分隔,比如:本文最初的例子中Software->Gallery->OnlineMarketplace表述为:":Software:Gallery:OnlineMarketplace", 第一个":"表示根.
而如果键值的名称包含空格等特殊字符的时候,如同命令行的转义字符一样,使用"/"来转义,比如: ":Software:Gallery:Online/ Marketplace".
PlistBuddy如果不使用"-c"参数,则进入人机交互模式, "-c"的意思就是执行它后面的命令列表,而命令如果有参数,需要把它们包含在引号中,
1.添加
plistbuddy -c 'Add :Software:Gallery:Version string "1.0"' ~/Desktop/com.sample.plist
2.输出
plistbuddy -c "Print" ~/Desktop/com.sample.plist
3.修改
plistbuddy -c 'Set :Software:Gallery:Version "1.1"' ~/Desktop/com.sample.plist
4.删除
plistbuddy -c 'Delete :Software:Gallery:Version' ~/Desktop/com.sample.plist
5.合并
plistbuddy -c "Merge ~/Desktop/Global.plist :Software:Gallery" ~/Desktop/com.sample.plist
用PlistBuddy修改Plist文件的更多相关文章
- Xcode下修改plist文件
plist文件在Mac OS下的重要性,如同Windows下的注册表文件.而很多场景下面,我们需要修改plist文件来实现一些"自动化"操作 Mac OS本身提供了一个工具:P ...
- Mac 下,修改plist文件
/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName $DISPLAY_NAME" "${PROJECT_TEMP_D ...
- cocos2d-x 读取.plist文件
转自:http://blog.csdn.net/hgplan/article/details/8629904 在cocos2d-x中可以用.plist格式的文件来保存数据,它是XML文件格式的一种,在 ...
- cocos2d-x 2.1 -- 读取.plist文件
在cocos2d-x中可以用.plist格式的文件来保存数据,它是XML文件格式的一种,在cocos2d-x解析.plist方面相关的资料比较少,但本身也很简单,要解析.plist文件可以参考coco ...
- iOS-代码修改Info.plist文件
解决办法: 1.首先系统的Info.Plist文件是只读文件 并不能 写入.目前我个人是没有办法存入,官方属性 可以看到是readOnly 2.那么我们 就想代码修改Info.Plist文件怎么办呢, ...
- script 修改 plist遇到的问题
一个sh脚本每次build的时候动态修改info.plist文件 达到动态更改版本号的目的 但是估计是因为缓存的缘故 每次只有clean之后再运行才会修改成功 看script执行的log 好像是先修改 ...
- plist文件、NSUserDefault 对文件进行存储的类、json格式解析
========================== 文件操作 ========================== Δ一 .plist文件 .plist文件是一个属性字典数组的一个文件: .plis ...
- plist文件的使用
什么是plist文件 直接将数据写在代码里面,不是一种合理的做法.如果经常改,就要经常翻开对应的代码进行修改,造成代码扩展性低 因此,可以考虑将经常变的数据放在文件中进行存储,程序启动后从文件中读取最 ...
- plist文件真机写入方法
http://blog.csdn.net/mydo/article/details/50290219 转 但是这对真机不管用,因为在真机环境下,App在Xcode中的Resources文件夹都是不可 ...
随机推荐
- Java多线程——线程的生命周期和状态控制
一.线程的生命周期 线程状态转换图: 1.新建状态 用new关键字和Thread类或其子类建立一个线程对象后,该线程对象就处于新生状态.处于新生状态的线程有自己的内存空间,通过调用start方法进入就 ...
- 汉字转拼音(pinyin4j-2.5.0.jar)
import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.pinyin4j.format.HanyuPinyinCase ...
- C++线性序列容器<vector>简单总结
C++线性序列容器<vector>简单总结 vector是一个长度可变的数组,使用的时候无须声明上限,随着元素的增加,Vector的长度会自动增加:Vector类提供额外的方法来增加.删除 ...
- start with connect by prior学习
这是oracle中的树查询,查询出来的数据会根据上下级组成树的结构.select * from mw_sys.mwt_pd_deps start with obj_id = '63EBEC8E-E76 ...
- java.sql.SQLException: ORA-00604: 递归 SQL 级别 1 出现错误
后台报出如下错误: Caused by: java.sql.SQLException: ORA-00604: 递归 SQL 级别 1 出现错误 ORA-01000: 超出打开游标的最大数 ORA-00 ...
- 以下是jQuery和JavaScript实现相同操作的等价代码。
选择元素 Javascript代码 1.// jQuery 2.var els = $('.el'); 3. 4.// 原生方法 5.var els = document.queryS ...
- String的format方法
摘自:http://xiongzhenhui.iteye.com/blog/940416 http://blueram.iteye.com/blog/441683 一.常规类型.字符类型和数值类型的格 ...
- C++拾遗(十二)C++代码重用
“has-a”关系 通常有两种方法实现: 1.被包含,本身是另一个类的对象. 2.私有或者保护继承. 主要讨论第二种方法,在继承时使用private关键字(或者不用任何关键字,默认就是私有的). 使用 ...
- Interview Algorithm
约瑟夫环: #include <stdio.h> #include <stdlib.h> #include <string.h> int find(int *arr ...
- Linux 从 sar 到 sar2html 的认识
这些变形的工具.诸如:淘宝的Tsar.ksar.sar2html....等.都是通过抓取 sar的数据 所以在最终呈现的数据上变化不大.只是展现的手段和效果不一样而已 sar 是帮助我们 ...