I want to add/replace the URL scheme in Info.plist file using bash script/command.
I tried with sed command with various patterns but not succeeded.
We want to automate the build generation using Jenkins and our URL Scheme can be changed for various builds, so we want to modify the Info.plist file such that we can either add a new URL Scheme if not there or replace the existing one using script/commands.
Please suggest the command to achieve this.
Xcode 9.2
1 create url scheme

in the run script (which is written below)
/usr/libexec/PlistBuddy -c "set :CFBundleURLTypes:1:CFBundleURLSchemes:0 $SCHEME" "$INFOPLIST_MYAPP"we have :CFBundleURLTypes:1
1 = item 1
2 add run script

INFOPLIST_MYAPP="${SRCROOT}/SM2/Application/InfoPlist/Info.plist"
SCHEME=""
case "${CONFIGURATION}" in
"Debug_Staging" | "AdHoc_Staging" | "Test_Staging" | "Profile_Staging" )
SCHEME="sm2dev" ;;
"Debug_Production" | "AdHoc_Production" | "Distribution" | "Test_Production" | "Profile_Production" )
SCHEME="sm2" ;;
*)
;;
esac
/usr/libexec/PlistBuddy -c "set :CFBundleURLTypes:1:CFBundleURLSchemes:0 $SCHEME" "$INFOPLIST_MYAPP"

You can use plutil tool
$INFO_PLIST_FILE=path_to_your_plist_file
$NEW_URL_STRING=new_url_string
echo "removing current url string"
plutil -remove CFBundleURLTypes.0.CFBundleURLSchemes.0 $INFO_PLIST_FILE
echo "updating with new url string"
plutil -replace CFBundleURLTypes.0.CFBundleURLSchemes.0 -string $NEW_URL_STRING $INFO_PLIST_FILE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With