macosshellconsoleplistproperty-list

modifying a Plist from command line on Mac using Defaults


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.

enter image description here

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?


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);}'