如何通过 AppleScript 将命令行参数传递给 Xcode 项目?

发布于 2024-09-28 00:27:56 字数 1826 浏览 3 评论 0原文

我正在尝试为与 iPhone 模拟器应用程序相关的 Xcode 项目设置命令行参数。

当我尝试运行以下脚本时,该行 “用属性创建新的启动参数{name:“file:///Users/aakash/Desktop/sample_h.html”,active:yes}”

给出错误: 执行错误: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 项目的参数还是我做错了? 请帮忙。

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 container. (-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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

卖梦商人 2024-10-05 00:27:56

对于从命令行构建,我通常使用启动 xcodebuild 的 Makefile,该命令Xcode 的线前端。如果您愿意,也可以使用 zsh 脚本来执行相同的操作。使用命令行工具设置项目构建选项非常容易。

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.

恰似旧人归 2024-10-05 00:27:56

您应该将活动可执行文件作为容器而不是 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.*

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.*

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文