How to store part of a plist to a file and then merge this to another plist?

772 Views Asked by At

I need to extract part of a plist, store this in a file and then later load / merge this saved portion into another plist, overwriting an existing key with its accompanying keys and values.

I understand that PlistBuddy helps the process dramatically as you can read a portion a key with its subkeys via: /usr/libexec/PlistBuddy -c "Print :KeyName" /path/to/some.plist

But it's not clear if you can simply use file redirection here to save the output and then reload it via the Merge command with the accompanying plist to insert or not.

An example of the commands would be much appreciated!

1

There are 1 best solutions below

0
ylluminate On

It appears that the following process can be followed to modify a plist with merged values:

# 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