How to access ${SRCROOT} in a user script?

一个人想着一个人 提交于 2019-12-25 06:43:19

问题


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?


回答1:


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'


来源:https://stackoverflow.com/questions/2143007/how-to-access-srcroot-in-a-user-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!