comparison ScriptingBridge_Xcode4_broken.lua @ 4:fdcbf6da59ec

Added non-working Xcode 4 scripting bridge script as a reference.
author Eric Wing <ewing@anscamobile.com>
date Mon, 08 Aug 2011 19:16:12 -0700
parents
children
comparison
equal deleted inserted replaced
3:d63043d62684 4:fdcbf6da59ec
1 #!/Library/Frameworks/LuaCocoa.framework/Versions/Current/Tools/luacocoa
2 --[[
3 Simple Scripting Bridge example using iTunes.
4 Script will launch iTunes (if not already open),
5 Pause playback (if not already paused),
6 Start/resume playing,
7 and print out the name, artist, year of the current track.
8 --]]
9
10 LuaCocoa.import("ScriptingBridge")
11 LuaCocoa.import("Foundation")
12
13 function GetURLFromFileAndPath(file_name)
14 local current_working_directory = NSFileManager:defaultManager():currentDirectoryPath()
15
16 local file_string = NSString:stringWithUTF8String_(file_name):stringByExpandingTildeInPath():stringByStandardizingPath()
17 if not file_string:isAbsolutePath() then
18 file_string = current_working_directory:stringByAppendingPathComponent_(file_string):stringByStandardizingPath()
19 end
20 --print("file_string", file_string)
21
22 local ns_url = NSURL:URLWithString_(file_string:stringByAddingPercentEscapesUsingEncoding_(NSUTF8StringEncoding))
23 --print("ns_url", ns_url)
24
25 return ns_url
26 end
27
28 local xcode_application = SBApplication:applicationWithBundleIdentifier_("com.apple.dt.Xcode")
29
30 if xcode_application ~= nil then
31 -- arg[0] is the script name
32 -- negative index values represent arguments that come before the script
33 -- we only want the arguments after the script name
34 -- so use a numeric for
35 local file_to_open = arg[1] or "MySampleProject.xcodeproj"
36 local url_to_open = GetURLFromFileAndPath(file_to_open)
37 local xcode_document = xcode_application:open(url_to_open)
38
39
40 --[[
41 local all_documents = xcode_application:projects()
42
43 print(all_documents, #all_documents)
44 for i=1, #all_documents do
45 local a_doc = all_documents[i]
46 print("doc", a_doc)
47 end
48 --]]
49
50 -- I'm assuming that the document we just opened becomes the activeProjectDocument
51 --[[ Broken in Xcode 4
52 local active_project_document = xcode_application:activeProjectDocument()
53 print("active_project", active_project_document )
54 print("active_project name", active_project_document:name())
55 print("active_project path", active_project_document:path())
56 --]]
57
58 NSLog("workspace docs %@", xcode_application:workspaceDocuments())
59 local workspace_documents = xcode_application:workspaceDocuments()
60
61 for i=1, #workspace_documents do
62 print("workspace_documents " .. workspace_documents[i]:name())
63 end
64
65 local active_workspace_document = xcode_application:activeWorkspaceDocument()
66 print("active_workspace_document name", active_workspace_document:name())
67
68 local active_workspace_document_projects = active_workspace_document:projects()
69 local xcode_project = nil
70 for i=1, #active_workspace_document_projects do
71 print("active_workspace_document_projects " .. active_workspace_document_projects[i]:name())
72 if tostring(active_workspace_document_projects[i]:name()) == "ratatouille" then
73 xcode_project = active_workspace_document_projects[i]
74 print("xcode_project set", xcode_project)
75 end
76 end
77
78
79
80 local xcode_project = active_project_document:project()
81 -- print("xcode project, name ", xcode_project, xcode_project:name())
82
83 local xcode_project_schemes = active_workspace_document:schemes()
84 NSLog("schemes %@, %d", xcode_project_schemes, xcode_project_schemes:count())
85 for i=1, #xcode_project_schemes do
86 print("xcode_project_schemes " .. xcode_project_schemes[i]:name())
87 end
88
89 -- This could be a problem: activeSDK() is nil. Looks like an Apple bug.
90 --print("activeSDK", xcode_project:activeSDK())
91 -- I don't think we need to worry about setting the architexture since we build Universal (fat)
92 --print("activeArchitecture", xcode_project:activeArchitecture())
93
94 -- I'm unclear on buildConfigurations vs buildConfigurationTypes
95 -- I don't think we need to use buildConfigurations
96 --[[
97 local array_of_build_configurations = xcode_project:buildConfigurations()
98 for i=1, #array_of_build_configurations do
99 print("buildConfigurations[:".. tostring(i) .. "]" .. array_of_build_configurations[i]:name())
100 end
101 --]]
102
103 local array_of_build_configuration_types = xcode_project:buildConfigurationTypes()
104 for i=1, #array_of_build_configuration_types do
105 print("buildConfigurationType[".. tostring(i) .. "]" .. array_of_build_configuration_types[i]:name())
106 end
107
108 local array_of_executables = xcode_project:executables()
109 for i=1, #array_of_executables do
110 print("executables[".. tostring(i) .. "]" .. array_of_executables[i]:name())
111 end
112
113 local array_of_targets = xcode_project:targets()
114 local active_target = xcode_project:activeTarget()
115 for i=1, #array_of_targets do
116 print("targets[".. tostring(i) .. "]" .. array_of_targets[i]:name())
117 -- Watch out: __eq (==) always returns false for different types.
118 local the_name = array_of_targets[i]:name()
119 -- if the_name:isEqualToString_("rttplayer-all") then
120 if tostring(the_name) == "rttplayer-all" then
121 active_target = array_of_targets[i]
122 end
123 end
124 xcode_project:setActiveTarget_(active_target)
125
126 local build_configuration_type = xcode_project:activeBuildConfigurationType()
127 print("config type", xcode_project:activeBuildConfigurationType():name())
128 -- print("Bypass")
129 ret_string = xcode_project:buildStaticAnalysis_transcript_using_(false, false, build_configuration_type)
130 -- xcode_project:launch()
131 print("Bypass2")
132
133 active_workspace_document:buildStaticAnalysis_transcript_using_(false, false, build_configuration_type)
134 -- active_workspace_document:debug()
135 do
136 return
137 end
138
139 --print("config type", xcode_project:activeBuildConfigurationType():name())
140
141 -- You are not allowed to create a new instance of XcodeBuildConfigurationType
142 -- Instead, you must use an object returned from the system.
143 -- It appears you cannot use copy or mutableCopy as they throw exceptions.
144 -- XcodeBuildConfigurationType = NSClassFromString("XcodeBuildConfigurationType")
145 -- local build_configuration_type = XcodeBuildConfigurationType:alloc():init()
146 -- copy and mutableCopy throw exceptions
147 local build_configuration_type = xcode_project:activeBuildConfigurationType()
148 build_configuration_type:setName_("Release")
149 xcode_project:setActiveBuildConfigurationType_(build_configuration_type)
150 print("config type", xcode_project:activeBuildConfigurationType():name())
151
152
153 local active_executable = xcode_project:activeExecutable()
154 print(active_executable, active_executable:name())
155 active_executable:setName_("rttplayer-all")
156
157 print("ActiveTarget:", xcode_project:activeTarget():name())
158 print("ActiveExecutable:", xcode_project:activeExecutable():name())
159 ret_string = xcode_project:buildStaticAnalysis_transcript_using_(false, false, build_configuration_type)
160
161 -- local build_configuration_type =
162
163 print(ret_string)
164 print("launching...")
165 -- Refetch the object just in case since we tried changing it
166 active_executable = xcode_project:activeExecutable()
167
168 -- launch() doesn't seem to actually work. We must use debug()
169 -- local ret_string = active_executable:launch()
170 local ret_string = active_executable:debug()
171 print(ret_string)
172
173
174 else
175 print("Xcode not available")
176 end
177
178