【问题标题】:How to store part of a plist to a file and then merge this to another plist?如何将部分 plist 存储到文件中,然后将其合并到另一个 plist?
【发布时间】:2017-06-20 00:53:47
【问题描述】:
我需要提取 plist 的一部分,将其存储在一个文件中,然后稍后将保存的部分加载/合并到另一个 plist 中,用其随附的键和值覆盖现有的键。
我知道PlistBuddy 极大地帮助了这个过程,因为您可以通过以下方式读取一个键的一部分及其子键:
/usr/libexec/PlistBuddy -c "Print :KeyName" /path/to/some.plist
但尚不清楚您是否可以在这里简单地使用文件重定向来保存输出,然后通过 Merge 命令重新加载它并附带要插入的 plist。
非常感谢您提供命令示例!
【问题讨论】:
标签:
macos
plist
macos-sierra
plistbuddy
【解决方案1】:
看来可以按照以下过程来修改具有合并值的plist:
# Get contents that you want to store:
/usr/libexec/PlistBuddy -x -c "Print :KeyYouWant" /path/to/plist_with_key_set_you_want.plist
# Merge the contents of the saved file to the other plist:
/usr/libexec/PlistBuddy -x -c "Merge plist_with_key_set_you_want.plist :KeyToMergeInto" /path/to/destination.plist