通过Applescript将文件添加到Xcode项目目标
发布时间:2020-12-14 17:48:57 所属栏目:百科 来源:网络整理
导读:我想自动将文件添加到从头创建的 Xcode项目(通过另一个IDE)作为构建后步骤.我们的项目设置为调用在项目中生成相应文件引用的applescript,但是每次尝试将文件引用添加到项目都会失败. 核心问题似乎是这个错误: Xcode出错:工作区文档“project.xcworkspace”
我想自动将文件添加到从头创建的
Xcode项目(通过另一个IDE)作为构建后步骤.我们的项目设置为调用在项目中生成相应文件引用的applescript,但是每次尝试将文件引用添加到项目都会失败.
核心问题似乎是这个错误: 在这条线上: 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发送了有关此问题的信息,结果证明这是一个错误.我已经提交了一份错误报告,希望这个问题很快得到解决.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |