0

I'm trying to change bundle display name via Xcode run script if a special condition is met. So far I have this:

if [ MY_CONDITION ]; then
BUNDLE_DISPLAY_NAME = ${BUNDLE_VERSION};

fi

I get this error

line 3: BUNDLE_DISPLAY_NAME: command not found

Where do I look up this fancy variable names? And is what I'm trying to do even possible with script?

NKorotkov
  • 3,591
  • 1
  • 24
  • 38
  • Wouldn't the display name be set in the `Info.plist` file? – trojanfoe Mar 23 '16 at 10:13
  • @trojanfoe you mean I can change the Bundle display name in the Info.plist file? Sure. But can I set up a conditional result there? I don't think so. Please guide me if I'm wrong. – NKorotkov Mar 23 '16 at 10:19
  • 1
    Yeah; you need to create a new *external tool* target (I think it's called that). This script then evaluates the condition and uses `Plistbuddy` to change the value in the `Info.plist` file. You then make your bundle target dependent on this external tool target. – trojanfoe Mar 23 '16 at 10:20

2 Answers2

0

Remove spaces around = symbol (BUNDLE_DISPLAY_NAME=${BUNDLE_VERSION};) otherwise bash interpret BUNDLE_DISPLAY_NAME as separate command and try to execute BUNDLE_DISPLAY_NAME, but not found this command. But bash interpret BUNDLE_DISPLAY_NAME=${BUNDLE_VERSION} as operation assign a value ${BUNDLE_VERSION} with variable BUNDLE_DISPLAY_NAME.

Stanislav P.
  • 145
  • 1
  • 7
0

For clarity and to officially put @trojanfoe's comment in an answer, BUNDLE_DISPLAY_NAME isn't a build variable. It's a value in your target's Info.plist. You'll need to change it there instead.

In order to keep your source control clean, you should put the following script after your Copy Bundle Resources phase.

if [ MY_CONDITION ]; then
  newDisplayName="${BUNDLE_VERSION}"
  command="Set :CFBundleDisplayName $newDisplayName"

  echo "Updating display name in app package to \"$newDisplayName\""
  /usr/libexec/PlistBuddy -c "$command" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"

  filepath="${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}.dSYM/Contents/Info.plist"
  if [ -f "$filepath" ]; then
    echo "Updating display name in dsym to \"$newDisplayName\""
    /usr/libexec/PlistBuddy -c "$command" "$filepath"
  fi;
fi
Jay Whitsitt
  • 937
  • 9
  • 27