通过Applescript将文件添加到Xcode项目目标

问题描述:

我想自动将文件添加到从头创建(通过另一个IDE)作为生成后步骤的Xcode项目。我们的项目被设置为调用一个applescript,在项目中创建适当的文件引用,但是每次将文件引用添加到项目中的尝试都会失败。通过Applescript将文件添加到Xcode项目目标

的核心问题似乎是这样的错误: Xcode中得到了一个错误:项目的Xcode 3组ID“D82DCFB50E8000A5005D6AD8”工作空间文档中的“TestProject”的文件参考ID“DCDCC17E13819A8E004B4E75”“project.xcworkspace”不明白添加消息。

在这条线:

add fileRef to first target of testProject 

哪里fileRef是设置为新创建的文件引用的变量,testProject是变量设置为包含fileRef项目。

下面是代码:

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 

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

仅供参考,我使用的是OSX 10.6.7和Xcode 4.0.2。

因此,我通过电子邮件向Apple发送了这个问题的电子邮件,结果证明这是一个错误。我已经提交了一个错误报告,希望这个问题很快就会得到解决。

+0

任何想法如何通过PHP sc将某些文件添加到XCode项目RIPT? – 2011-10-06 18:43:30

+0

据我所知,通过程序与XCode进行通信的唯一方法是通过Applescript,也许你的PHP脚本可以调用某种Applescript?但我真的不知道PHP是如何工作的。 – Reuben 2011-10-22 01:47:54

+0

您最近是否检查过该雷达的雷达?状态是否已更新? – ThomasW 2012-01-25 02:32:00

更改此:

- 添加文件引用生成目标 添加fileRef到testProject

的第一目标是:

- 文件引用添加到构建目标 告诉应用程序“Xcode” 添加fileRef到testProject的第一个目标 end tell