Build and Run an xcode project via AppleScript

后端 未结 4 546
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-13 11:13

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

4条回答
  •  时光取名叫无心
    2020-12-13 12:02

    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 <
    
                                     
                  
提交回复
热议问题