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:
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"
}
I don't want to overwrite any existing settings though. How do I add these settings to the end of PreferenceSpecifiers?
I have read the documentation, and I have tried using Merge to no success.
$PLISTBUDDY -c "Merge ${PROJECT_DIR}/Settings1.bundle/Root.plist" "$SETTINGSBUNDLEPATH"
Edit: added 'try-catch'es to the code, this fixes the issue when running the script twice.