读取plist文件--PlistBuddy
一、建
cd 指定路径
touch test.plist
echo "<?xml version="1.0" encoding="UTF-8"?><plist version="1.0"><dict></dict></plist>" > test.plist
二、增
数据类型string、array、dict、bool、real、integer、date、data
/usr/libexec/PlistBuddy -c 'Add :key type value' test.plist 添加任意元素,type为上述六种类型之一
/usr/libexec/PlistBuddy -c 'Add :key array' test.plist 添加一个数组到plist
/usr/libexec/PlistBuddy -c 'Add :arraykey:index string value' test.plist 添加一个字符串到指定数组指定下标
/usr/libexec/PlistBuddy -c 'Add :dictkey:key string value' test.plist 添加一个键值对到plist指定字典中
三、删
/usr/libexec/PlistBuddy -c 'Delete key ' test.plist 删除任意元素
/usr/libexec/PlistBuddy -c 'Delete array:index ' test.plist 删除数组元素中指定下标的元素
/usr/libexec/PlistBuddy -c 'Delete dictkey:key' test.plist 删除字典元素中指定key的元素
四、改
/usr/libexec/PlistBuddy -c 'Set :key changevalue' test.plist 修改任意元素
/usr/libexec/PlistBuddy -c 'Set :dictkey:key changevalue' test.plist 修改指定字典元素指定key的值
/usr/libexec/PlistBuddy -c 'Set :arraykey:index changevalue' test.plist 修改数组元素中指定下标的值
五、查
/usr/libexec/PlistBuddy -c 'Print key' test.plist 查各种类型的value
/usr/libexec/PlistBuddy -c 'Print arraykey:index' test.plist 查数组元素中下标index的值
/usr/libexec/PlistBuddy -c 'Print dictkey:key' test.plist 查字典元素key的值
六、其他
/usr/libexec/PlistBuddy -c "Clear" test.plist 删除plist中所有元素
/usr/libexec/PlistBuddy -c "Merge test1.plist" test.plist 合并2个plist文件的值
#/usr/libexec/PlistBuddy -c "Copy :key1: key2" test.plist 复制key1的值为key2的值(不能覆盖所以key2需为之前不存在的key)
/usr/libexec/PlistBuddy -c "Import :key file" test.plist 把文件设置key的值
/usr/libexec/PlistBuddy -help 查看plistbuddy帮助