通过AppleScript构建并运行xcode项目

pro*_*rey 10 iphone xcode applescript

我正在尝试构建一个xcode项目并通过iPhone模拟器通过AppleScript运行它.我知道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
Run Code Online (Sandbox Code Playgroud)

...但是build命令似乎没有服从活动的SDK属性,它总是默认为项目的基本SDK设置(例如iPhoneOS3.0而不是iPhonesimulator3.0)

有没有办法告诉build命令使用特定的SDK?我在雪豹上使用xcode 3.2.

pro*_*rey 12

这是诀窍......您必须设置SDKROOT构建设置.这是一个zsh脚本,我用它来查找当前层次结构中的xcode项目,构建它,并通过xcode运行它.

#!/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

# 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
Run Code Online (Sandbox Code Playgroud)