如何在用户脚本中访问 ${SRCROOT}? [英] How to access ${SRCROOT} in a user script?

查看:32
本文介绍了如何在用户脚本中访问 ${SRCROOT}?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户脚本,我希望能够访问 $SRCROOT 以获取属于项目但无法使其工作的文件.如果我创建一个简单的用户脚本:回声${SRCROOT}"将输出设置为替换选择,除了换行符外,没有任何输出.

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?

推荐答案

是的,您可以从用户脚本访问环境变量,但问题是 SRCROOT 是构建设置,而不是环境变量.它仅在构建时有效,在编辑时无效.

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.

如果您想要的是最前面项目的位置,则以下行会将其写入标准输出.您可以使用标准的 shell 路径处理来获取您想要的内容.

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'

这篇关于如何在用户脚本中访问 ${SRCROOT}?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆