建立和运行的AppleScript通过一个x code项目 [英] Build and Run an xcode project via AppleScript

查看:228
本文介绍了建立和运行的AppleScript通过一个x code项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个x code项目,并通过iPhone模拟器通过AppleScript的运行它。我知道的 X codebuild ,但它不会让你运行在模拟器的应用程序。我已经得到了pretty密切与下面的脚本...

I'm trying to build an xcode project and run it through the iPhone Simulator via applescript. I'm aware of xcodebuild but it doesn't let you run the app in the simulator. I've gotten pretty close with the script below...

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

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

... but the build command doesn't seem to obey the active SDK property, it always defaults to the project's base SDK setting (such as the iPhoneOS3.0 instead of iPhonesimulator3.0)

有没有办法告诉编译命令为使用特定的SDK?我使用雪豹x $ C $ 3.2Ç

Is there a way to tell the build command to use a specific SDK? I'm using xcode 3.2 on snow leopard.

推荐答案

下面是招...你必须设置SDKROOT构建设置。这里是一个脚本的zsh我用查找当前层次结构中的X code项目,构建它,并通过X code运行它。

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.

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

这篇关于建立和运行的AppleScript通过一个x code项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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