通过 AppleScript 构建和运行 xcode 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1514302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Build and Run an xcode project via AppleScript
提问by probablyCorey
I'm trying to build an xcode project and run it through the iPhone Simulator via applescript. I'm aware of xcodebuildbut it doesn't let you run the app in the simulator. I've gotten pretty close with the script below...
我正在尝试构建一个 xcode 项目并通过 Applescript 通过 iPhone 模拟器运行它。我知道xcodebuild但它不允许您在模拟器中运行该应用程序。我已经非常接近下面的脚本了......
tell application "Xcode"
set targetProject to project of active project document
tell targetProject
set active build configuration type to build configuration type "Debug"
set active SDK to "iphonesimulator3.0"
end tell
if (build targetProject) is equal to "Build succeeded" then
launch targetProject
end if
end tell
... but the build command doesn't seem to obey the active SDKproperty, it always defaults to the project's base SDK setting (such as the iPhoneOS3.0 instead of iPhonesimulator3.0)
...但构建命令似乎不遵守active SDK属性,它始终默认为项目的基本 SDK 设置(例如 iPhoneOS3.0 而不是 iPhonesimulator3.0)
Is there a way to tell the build command to use a specific SDK? I'm using xcode 3.2 on snow leopard.
有没有办法告诉构建命令使用特定的 SDK?我在雪豹上使用 xcode 3.2。
回答by probablyCorey
Here is the trick... you have to set the SDKROOT build setting. Here is a zsh script I use to find the xcode project within the current hierarchy, build it, and run it via xcode.
这是诀窍……您必须设置 SDKROOT 构建设置。这是我用来在当前层次结构中查找 xcode 项目、构建它并通过 xcode 运行它的 zsh 脚本。
#!/bin/zsh
BUILD_PATH=$(dirname ##代码##)
while [[ -z $BUILD_FILE && $BUILD_PATH != "/" ]]; do
BUILD_FILE=$(find $BUILD_PATH -name '*.xcodeproj' -maxdepth 1)
BUILD_PATH=$(dirname $BUILD_PATH)
done
if [[ -z $BUILD_FILE ]]; then
echo "Couldn't find an xcode project file in directory"
exit 1
fi
# Applescript likes's : instead of / (because it's insane)
BUILD_FILE=${BUILD_FILE//\//:}
# Find the latest Simulator SDK
SIMULATOR_SDKS=( /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/*.sdk )
SIMULATOR_SDK=${SIMULATOR_SDKS[-1]}
SIMULATOR_SDK_STRING=$(basename ${(L)SIMULATOR_SDK%.[a-z]*})
if [[ -z $SIMULATOR_SDK ]]; then
echo "Couldn't find a simulator SDK"
exit 1
fi
osascript <<SCRIPT
application "iPhone Simulator" quit
application "iPhone Simulator" activate
tell application "Xcode"
open "$BUILD_FILE"
set targetProject to project of active project document
tell targetProject
set active build configuration type to build configuration type "Debug"
set active SDK to "$SIMULATOR_SDK_STRING"
set value of build setting "SDKROOT" of build configuration "Debug" of active target to "$SIMULATOR_SDK"
if (build targetProject) is equal to "Build succeeded" then
launch targetProject
else
application "iPhone Simulator" quit
end if
end tell
end tell
SCRIPT
回答by Dave DeLong
Another option to consider is to use Applescript to launch a shell script that executes the xcodebuild
program. xcodebuild
allows you to specify things like a specific target, configuration, sdk, etc. I use this all the time when I have to SSH into a build server and rebuild a project.
另一个要考虑的选择是使用 Applescript 来启动一个执行xcodebuild
程序的 shell 脚本。 xcodebuild
允许您指定诸如特定目标、配置、sdk 等内容。当我必须通过 SSH 连接到构建服务器并重建项目时,我一直使用它。
回答by ThomasW
回答by Nikolai Ruhe
If the set active SDK
command does not work as expected, a workaround would be to create another build configuration named "Debug-Simulator" (in Xcode in the project settings), and to set the base SDK in the new configuration to iphonesimulator3.0. This would allow you to select the SDK by selecting the build configuration (if that works in AppleScript).
如果该set active SDK
命令没有按预期工作,解决方法是创建另一个名为“Debug-Simulator”的构建配置(在项目设置的 Xcode 中),并将新配置中的基本 SDK 设置为 iphonesimulator3.0。这将允许您通过选择构建配置来选择 SDK(如果在 AppleScript 中有效)。