繁体   English   中英

如何通过AppleScript将命令行参数传递给Xcode项目?

[英]How do i pass command line arguments to Xcode project through AppleScript?

我正在尝试为与iPhone Simulator Application相关的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 Project设置参数,还是我做错了? 请帮忙。

为了从命令行进行构建,我通常使用Makefile来启动xcodebuild ,这是Xcode的命令行前端。 如果愿意,还可以使用zsh脚本执行相同的操作。 使用命令行工具设置项目构建选项非常容易。

您应该使活动可执行文件作为容器而不是Xcode应用程序

tell application "Xcode"
set targetProject to project of active project document
set targetExecutable to active executable of targetProject
tell targetExecutable
make new launch argument with properties {name:"new argument", active:true}
end tell
end tell


这仍然适用于Xcode 3. *,但不再适用于Xcode 4. *

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM