views:

184

answers:

1

I have a user script that I would like to be able to access $SRCROOT in order to get a file that is part of the project but can't see to get it to work. If I create a simple user script as so: echo "${SRCROOT}" with the output set to replace selection nothing is output except the newline.

Is there a way to access env vars from user scripts?

+2  A: 

Yes, you can access environment variables from user scripts, but the problem is that SRCROOT is a build setting, not an environment variable. It's only valid at build time, not at editing time.

If what you want is the location of the frontmost project, the following line will write that to stdout. You can use standard shell path processing to get what you want from it.

#!/bin/sh
osascript -e 'tell application "Xcode"' -e 'full path of project of active project document' -e 'end tell'
cdespinosa
That worked beautifully! Thanks, didn't think to use Applescript.
tgunr