我想自動將文件添加到從頭創建(通過另一個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。
任何想法如何通過PHP sc將某些文件添加到XCode項目RIPT? – 2011-10-06 18:43:30
據我所知,通過程序與XCode進行通信的唯一方法是通過Applescript,也許你的PHP腳本可以調用某種Applescript?但我真的不知道PHP是如何工作的。 – Reuben 2011-10-22 01:47:54
您最近是否檢查過該雷達的雷達?狀態是否已更新? – ThomasW 2012-01-25 02:32:00