开发者

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

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 cont开发者_如何转开发ainer. (-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.


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.


You should make active executable as the container instead of Xcode application

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


this still works for Xcode 3.* but no long work with Xcode 4.*

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜