modifying a Plist from command line on Mac using Defaults

console, macos, plist, property-list, shell

Solution

Open the Info.plist in a text editor to see the actual identifiers.

defaults write Absolute/Path/to/Info.plist CFBundleURLTypes -array-add '<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>Mac App Store URL</string>
<key>CFBundleURLSchemes</key>
<array>
<string>macappstore</string>
</array>
</dict>'

`pbpaste | pl` converts the XML to the old-style format.

`defaults write Info.plist CFBundleURLTypes -array-add '{CFBundleTypeRole=Viewer; FBundleURLName="Mac App Store URL";CFBundleURLSchemes=(macappstore);}'`

Problem

Does any one know how to modify a Plist file from command line using defaults? Currently there are two Dictionaries under the `URL types` array; I need to add another. Every command i've tried have either replaced the entire dictionary, or created a new array called `URL types` instead of editing it. Any ideas of how this can be done in defaults (the console Mac app) and not PlistBuddy?

Original source

Related problems