Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add/Replace URL Scheme in Info.plist using bash script

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.

like image 731
patel kavit Avatar asked Jun 25 '26 05:06

patel kavit


2 Answers

Task

  • set different url schemes for staging/production

Details

Xcode 9.2

Solution

1 create url scheme

enter image description here

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

enter image description here

2 add run script

enter image description here

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"

All Project Schemes

enter image description here

like image 175
Vasily Bodnarchuk Avatar answered Jun 27 '26 17:06

Vasily Bodnarchuk


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
like image 31
Josh Avatar answered Jun 27 '26 17:06

Josh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!