2010-10-20 54 views
0

我想爲iPhone模擬器應用程序相關的Xcode項目設置命令行參數。如何通過AppleScript將命令行參數傳遞給Xcode項目?

當我嘗試運行下面的腳本行 「做出新的發射參數與性能{名:」文件:///Users/aakash/Desktop/sample_h.html「活動:是}」

給出錯誤: 執行錯誤: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項目的參數還是我做錯了? 請幫忙。

回答

0

對於從命令行構建,我通常使用Makefile啓動xcodebuild,它是Xcode的命令行前端。如果你願意,你也可以使用zsh腳本來做同樣的事情。使用命令行工具設置項目構建選項非常簡單。

+0

xcodebuild聯編不與iPhone合作模擬器應用程序。您必須在Xcode中啓動「build and go」來運行應用程序。 – Freakotrotter 2010-10-20 15:56:40

0

您應積極可執行文件作爲容器,而不是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 *

相關問題