1

Is it possible to run a shell script and use its result as a user defined macro in Xcode?

Basically I just want the result of a shell script to be put in a variable so it gets set in Info.plist (just like ${EXECUTABLE_NAME} etc.)

For example: If I add $(/usr/bin/whoami) as a build setting condition (at the bottom of settings of the build configuration) it just sets an empty string.

2 Answers2

1

Assuming a bash like shell, and given an almost complete lack of context for your problem, try

EXECUTABLE_NAME=$( scriptToGetEXEC_NAME )
PRODUCT_NAME=$( scriptToGetPROD_NAME)

The $( ... cmd ... ) construct is called command substitution. What this means is the when the shell processor scans each line of code, if first looks to see if there are any $(...) embedded (and other things to). If there are, it spawns a new shell, executes the code inside, and if any text is returned, it is embedded in the command line and THEN the shell scans the line again, and eventually executes everything from left to right, assuming that the first word will turn into a built-in command or a command in the PATH.

I hope this helps.

P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.

shellter
  • 36,525
  • 7
  • 83
  • 90
  • I edited the question, hopefully better explained this time. I tried what you said (creating a macro `$(/usr/bin/whoami)`) but it didn't get saved in my Info.plist –  Aug 26 '11 at 13:54
1

See this question for a couple of different approaches. All of them require add a "Run Script" build phase.

Community
  • 1
  • 1
Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • 1
    I added a run script which runs `export FOO=bar`, dragged it in front of all other build-phases and added `${FOO}` in my Info.plist but it didn't get set. (Sorry for posting this here but I can't comment on your link) –  Aug 26 '11 at 15:44
  • 4
    A sub-shell cannot modify the current environment, so that isn't surprising. The way I generally do this is by running a script that modifies `Info.plist` directly using sed or perl. – Rob Napier Aug 26 '11 at 15:54