title: How can I use PlistBuddy to add settings without overriding existing ones?
body: <p>I am trying to write a script that adds settings to the Settings app during build time without overwriting the existing ones, if existing. Here is a snippet of my script:</p>
  
  <pre><code>PLISTBUDDY="/usr/libexec/PlistBuddy"
  SETTINGSBUNDLEPATH="$CODESIGNING_FOLDER_PATH/Settings.bundle/Root.plist"
  
  {
  $PLISTBUDDY -c "Add :PreferenceSpecifiers:0:Type string 'PSGroupSpecifier'" "$SETTINGSBUNDLEPATH"
  $PLISTBUDDY -c "Add :PreferenceSpecifiers:0:Title string 'Version Information'" "$SETTINGSBUNDLEPATH"
  } || {
  $PLISTBUDDY -c "Set :PreferenceSpecifiers:0:Type 'PSGroupSpecifier'" "$SETTINGSBUNDLEPATH"
  $PLISTBUDDY -c "Set :PreferenceSpecifiers:0:Title 'Version Information'" "$SETTINGSBUNDLEPATH"
  }
  
  {
  $PLISTBUDDY -c "Add :PreferenceSpecifiers:1:Type string 'PSTitleValueSpecifier'" "$SETTINGSBUNDLEPATH"
  $PLISTBUDDY -c "Add :PreferenceSpecifiers:1:Title string 'Version:'" "$SETTINGSBUNDLEPATH"
  $PLISTBUDDY -c "Add :PreferenceSpecifiers:1:Key string 'appVersion'" "$SETTINGSBUNDLEPATH"
  $PLISTBUDDY -c "Add :PreferenceSpecifiers:1:DefaultValue string '$APPVERSION'" "$SETTINGSBUNDLEPATH"
  } || {
  $PLISTBUDDY -c "Set :PreferenceSpecifiers:1:Type 'PSTitleValueSpecifier'" "$SETTINGSBUNDLEPATH"
  $PLISTBUDDY -c "Set :PreferenceSpecifiers:1:Title 'Version:'" "$SETTINGSBUNDLEPATH"
  $PLISTBUDDY -c "Set :PreferenceSpecifiers:1:Key 'appVersion'" "$SETTINGSBUNDLEPATH"
  $PLISTBUDDY -c "Set :PreferenceSpecifiers:1:DefaultValue '$APPVERSION'" "$SETTINGSBUNDLEPATH"
  }
  </code></pre>
  
  <p>I don't want to overwrite any existing settings though. <strong>How do I add these settings to the end of PreferenceSpecifiers?</strong></p>
  
  <p>I have read the <a href="https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man8/PlistBuddy.8.html" rel="nofollow">documentation</a>, and I have tried using Merge to no success.</p>
  
  <pre><code>$PLISTBUDDY -c "Merge ${PROJECT_DIR}/Settings1.bundle/Root.plist" "$SETTINGSBUNDLEPATH"
  </code></pre>
  
  <p>Edit: added 'try-catch'es to the code, this fixes the issue when running the script twice.</p>