我正在尝试使用 rb-appscript 自动将文件添加到我的 Xcode 项目中。我对 Ruby 或 Applescript 没有太多经验,但似乎有两个人为他们完成了这项工作:
https://github.com/gonzoua/xcs/blob/master/xcs.thor
不幸的是,这些都不适合我。我可以让他们将文件添加到组,但将文件添加到目标会中断。这是对我不起作用的最简单的代码:
require 'rubygems'
require 'appscript'
project_path = 'Users:me:Projects:xcode:project:src:AppScaffold.xcodeproj'
project_name = 'AppScaffold'
group_name = 'Classes'
file_name = 'ApplicationDelegate.m'
target_name = 'AppScaffold'
def lookup(sequence, name)
sequence.get.each { |item|
if item.name.get == name
return item
end
}
raise Exception.new("Couldn't find name '" + name + "' in sequence " + sequence.inspect)
end
app = Appscript.app('Xcode')
app.open(project_path)
project = lookup(app.projects, project_name)
target = lookup(project.targets, target_name)
group = lookup(project.root_group.item_references, group_name)
file = lookup(group.item_references, file_name)
file.add({:to => target})
# I also tried this:
# app.add(file, {:to => target})
此消息失败:
/Library/Ruby/Gems/1.8/gems/rb-appscript-0.6.1/lib/appscript.rb:542:in `_send_command': CommandError (Appscript::CommandError)
OSERROR: -1708
MESSAGE: Application could not handle this command.
COMMAND: app("/Developer/Applications/Xcode.app").workspace_documents["project.xcworkspace"].projects["AppScaffold"].root_group.Xcode_3_groups.ID("080E96DDFE201D6D7F000001").Xcode_3_file_references.ID("1D3623250D0F684500981E51").add({:to=>app("/Developer/Applications/Xcode.app").workspace_documents["project.xcworkspace"].projects["AppScaffold"].targets.ID("1D6058900D05DD3D006BFB54")})
from /Library/Ruby/Gems/1.8/gems/rb-appscript-0.6.1/lib/appscript.rb:642:in `method_missing'
from add_to_target.rb:28
请注意,我使用的是 Xcode 4,但我的项目似乎有“Xcode_3_references”。我从头开始创建的项目也是如此;我不确定为什么。
无论如何,我不确定如何处理此错误消息,或者在哪里可以找到有关此的文档。(我查看了 Xcode 字典,但它没有太多关于“添加”的内容。)任何建议都会很棒。我没有嫁给 rb-appscript,我只想以编程方式将文件添加到我的项目中。