如何通过 AppleScript 将命令行参数传递给 Xcode 项目?
我正在尝试为与 iPhone 模拟器应用程序相关的 Xcode 项目设置命令行参数。
当我尝试运行以下脚本时,该行 “用属性创建新的启动参数{name:“file:///Users/aakash/Desktop/sample_h.html”,active:yes}”
给出错误: 执行错误:Xcode 出现错误:无法将该元素制作或移动到该容器中。 (-10024)
这是脚本:
!/bin/zsh
BUILD_PATH=$(dirname $0)
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
open -a Xcode "$BUILD_FILE"
BUILD_FILE=${BUILD_FILE//\//:}
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
echo $BUILD_FILE
echo $BUILD_PATH
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"
make new launch argument with properties{name:"file:///Users/aakash/Desktop/sample_h.html",active:no}
if (build targetProject) is equal to "Build succeeded" then
launch targetProject
else
application "iPhone Simulator" quit
end if
end tell
end tell
SCRIPT
有任何线索吗??? 还有其他方法可以设置 Xcode 项目的参数还是我做错了? 请帮忙。
I am trying to set command line arguments for Xcode project related to iPhone Simulator Application.
When i try to run the following script the line
"make new launch argument with properties{name:"file:///Users/aakash/Desktop/sample_h.html",active:yes} "
gives error:
execution error: Xcode got an error: Can’t make or move that element into that container. (-10024)
Here's the script:
!/bin/zsh
BUILD_PATH=$(dirname $0)
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
open -a Xcode "$BUILD_FILE"
BUILD_FILE=${BUILD_FILE//\//:}
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
echo $BUILD_FILE
echo $BUILD_PATH
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"
make new launch argument with properties{name:"file:///Users/aakash/Desktop/sample_h.html",active:no}
if (build targetProject) is equal to "Build succeeded" then
launch targetProject
else
application "iPhone Simulator" quit
end if
end tell
end tell
SCRIPT
Any Clues???
Is there any other way to set arguments for Xcode Project or am i doing it wrong?
Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于从命令行构建,我通常使用启动 xcodebuild 的 Makefile,该命令Xcode 的线前端。如果您愿意,也可以使用 zsh 脚本来执行相同的操作。使用命令行工具设置项目构建选项非常容易。
For building from the command line, I generally use a Makefile that launches xcodebuild, the command-line front-end to Xcode. You could also use a zsh script to do the same thing, if you prefer. It's pretty easy to set project build options using the command-line tool.
您应该将活动可执行文件作为容器而不是 Xcode 应用程序
这仍然适用于 Xcode 3.*,但不再适用于 Xcode 4.*
You should make active executable as the container instead of Xcode application
this still works for Xcode 3.* but no long work with Xcode 4.*