Posted on 11-14-2019 09:44 AM
I'm trying to write a plist from a bash script that has multiple nested dictionaries (dictionary within a dictionary within an array for example).
Right now I'm using the defaults command, which works for normal keys and dictionaries/arrays, but doesn't seem to have support for nested dictionaries/arrays. I need the script to run independently on any mac, so I can't use third party tools that don't come preinstalled on MacOS.
The structure I want to achieve is similar to this image.
Posted on 11-14-2019 03:03 PM
Google using /usr/libexec/PlistBuddy it's in there but hidden away and pretty sure it can do nested stuff.
Posted on 11-14-2019 03:29 PM
NM
Posted on 11-14-2019 07:42 PM
PlistBuddy
is a plist editor binary that can do nested values, but PlistBuddy
is not cfprefsd
aware, meaning you will have to kill the app after changing it for the changes to take effect. Just so you don't lose sleep over this small difference thought I would post it.
Posted on 11-15-2019 07:33 AM
It's not well known (I only discovered it recently), but plutil
is able to add or insert various values into plist, including adding arrays and entries to those. Here's a page that discusses using it that might help: https://scriptingosx.com/2016/11/editing-property-lists/
They even suggest that it's a good potential replacement to PlistBuddy.
Edit: Just wanted to add that plutil
also may not be cfprefsd aware, so it could require restarting cfprefsd
to get the altered values read in.
Posted on 11-15-2019 08:20 AM
@evangardner Show us the actual xml.