gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 13:42:32 27 4
gpt4 key购买 nike

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

核心问题似乎是这个错误:
Xcode 出现错误:工作区文档“project.xcworkspace”的项目“TestProject”的 Xcode 3 组 ID“D82DCFB50E8000A5005D6AD8”的文件引用 ID“DCDCC17E13819A8E004B4E75”不理解添加消息。

在这一行:

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 发了电子邮件,结果证明这是一个错误。我已经提交了一个错误报告,所以希望这个问题能很快得到解决。

关于xcode - 通过 Applescript 将文件添加到 Xcode 项目目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6022009/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com