Skip to main content
Question

How to write a plist with nested dictionaries from bash script


Forum|alt.badge.img+1

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.

5 replies

Forum|alt.badge.img+16
  • Valued Contributor
  • 1002 replies
  • November 14, 2019

Google using /usr/libexec/PlistBuddy it's in there but hidden away and pretty sure it can do nested stuff.


donmontalvo
Forum|alt.badge.img+36
  • Legendary Contributor
  • 4293 replies
  • November 14, 2019

NM


Forum|alt.badge.img+31
  • Honored Contributor
  • 2721 replies
  • November 15, 2019

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.


mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • November 15, 2019

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.


Forum|alt.badge.img+18
  • Contributor
  • 475 replies
  • November 15, 2019

@evangardner Show us the actual xml.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings