通过添加文件的AppleScript到X code项目目标 [英] Adding files via Applescript to an Xcode project target

查看:265
本文介绍了通过添加文件的AppleScript到X code项目目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要自动将文件添加到正在从头开始创建(通过另一个IDE)作为生成后步骤一个X code项目。我们的项目被设置为调用一个AppleScript,使该项目的相应的文件引用,但每次尝试将文件引用添加到项目失败。

问题的核心似乎是这个错误:
X $ C $Ç得到了一个错误:X code 3组ID项目D82DCFB50E8000A5005D6AD8工作区文件TestProjectproject.xcworkspace不理解附加信息的文件参考IDDCDCC17E13819A8E004B4E75

在这条线:

 添加到fileRef的testProject第一目标

其中fileRef是设定为新创建的文件参照的变量,和testProject是可变设定到包含fileRef项目

下面是code:

 上运行的argv - 获得要添加到项目中包含的项目的文件夹
告诉应用程序发现者
    设置thisScript为路径我
    集projectFolder得到thisScript的文件夹弦
    设置sourceFolder为projectFolder&安培; FilesToAdd:
告诉结束 - 获取所有将被添加到X code中的文件
告诉应用程序系统事件
    设置filesToAddList到每个磁盘项的名称(如sourceFolder化名)
告诉结束告诉应用程序X code
     - 使用POSIX风格的路径打开项目
    开(projectFolder的(POSIX路径)及TestProject.x codeproj)     - 给X code语言带来的时候,我们开始给它命令之前打开项目
    延迟1    设置testProject项目TestProject
    告诉testProject
        设置源组到组源
        告诉源组
             - 遍历所有的文件列表
            与我重复filesToAddList                设置文件名,(我的内容)                 - 使用Unix风格路径获取文件的路径,因为这是一种是X code需求
                设置文件路径至(sourceFolder的POSIX路径)及文件名                 - 不要添加重复文件引用
                如果文件路径是不是在源组文件引用的路径,然后
                     - 添加新的文件参考项目
                    设置fileRef使与性能的新文件引用{name:文件名,完整路径:文件路径,路径类型:绝对路径:文件路径,文件编码:MacOS的罗马}                     - 文件引用添加到构建目标
                    添加到fileRef的testProject第一目标
                万一
            重复结束        最终告诉我们 - 端基告诉    最终告诉我们 - 最终的项目告诉最终告诉我们 - 最终的应用程序告诉运行结束

我抬头将文件添加到目标的其他例子,而且好像这是做它的干净和简洁的方式,似乎已经奏效,在过去其他人。是否有不同的方式,文件的引用应该被添加到目标?

有关参考,我运行OSX 10.6.7和X code 4.0.2。


解决方案

所以我给苹果公司这个问题,它原来是一个错误。我已经提交一个bug报告,所以希望这个问题将得到尽快解决。

I want to automatically add files to an Xcode project that is created from scratch (through another IDE) as a post-build step. Our project is set up to call an applescript that makes the appropriate file references in the project, but every attempt to add the file references to the project fails.

The core problem seems to be this error: Xcode got an error: file reference id "DCDCC17E13819A8E004B4E75" of Xcode 3 group id "D82DCFB50E8000A5005D6AD8" of project "TestProject" of workspace document "project.xcworkspace" doesn’t understand the add message.

on this line:

add fileRef to first target of testProject

Where fileRef is the variable set to the newly-created file reference, and testProject is the variable set to the project containing the fileRef.

Here is the code:

on run argv

-- Get the folder containing items to be added to the project
tell application "Finder"
    set thisScript to path to me
    set projectFolder to get folder of thisScript as string
    set sourceFolder to projectFolder & "FilesToAdd:"
end tell

-- Get all the files that will be added to Xcode
tell application "System Events"
    set filesToAddList to the name of every disk item of (sourceFolder as alias)
end tell

tell application "Xcode"
    -- Open the project using posix-style paths
    open ((POSIX path of projectFolder) & "TestProject.xcodeproj")

    -- Give Xcode some time to open the project before we start giving it commands
    delay 1

    set testProject to project "TestProject"
    tell testProject
        set sourceGroup to group "Sources"
        tell sourceGroup
            -- Iterate over all files in the list
            repeat with i in filesToAddList

                set fileName to (contents of i)

                -- Get the file path using Unix-style pathing, since that is the kind that Xcode needs
                set filePath to (POSIX path of sourceFolder) & fileName

                -- Don't add duplicate file references
                if filePath is not in path of file references in sourceGroup then
                    -- Add a new file reference to the project
                    set fileRef to make new file reference with properties {name:fileName, full path:filePath, path type:absolute, path:filePath, file encoding:macos roman}

                    -- Add the file reference to the build target
                    add fileRef to first target of testProject
                end if
            end repeat

        end tell -- end group tell

    end tell -- end project tell

end tell -- end app tell

end run

I've looked up other examples of adding files to targets, and it seems like this is the cleanest and concise way of doing it, and it seems to have worked for other people in the past. Is there a different way that file references are supposed to be added to targets?

For reference, I'm running OSX 10.6.7 and Xcode 4.0.2.

解决方案

So I emailed Apple about this problem, and it turns out to be a bug. I've submitted a bug report, so hopefully this issue will get fixed soon.

这篇关于通过添加文件的AppleScript到X code项目目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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