Yes, you can access environment variables from user scripts, but the problem is that SRCROOT is a build parameter, not an environment variable. It is valid only during assembly, and not during editing.
If you need the location of the very first project, the next line will write this 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'
source
share