Re: XCode Scripts Menu item examples
Re: XCode Scripts Menu item examples
- Subject: Re: XCode Scripts Menu item examples
- From: Motti Shneor <email@hidden>
- Date: Thu, 26 Nov 2009 02:11:20 -0500
- Acceptlanguage: en-US
- Thread-topic: XCode Scripts Menu item examples
Thanks Matt, great finding. It is an excellent example of Xcode scripting and use of its dictionary --- exactly what I was looking for, but (and there always is a but...) there's nothing about PROJECT TEMPLATES there, I'm afraid.
This example shows how to construct the whole project thing programmatically. I, on the other hand, am trying to defer the "knowledge of the project" from code into a project template, so it can be maintained by non-scripter software engineers in our company, and so keep up with our infrastructure changes, and XCode/Compiler changes.
We'd like to open a template in XCode, modify it it using the UI, save it, and have all subsequent new projects follow the new rules.
I now managed to write a script that will make XCode create a new project from a template, using generic UI scripting. This was no easy task, but it is done now. I include the script below for the benefit of the oppressed XCode scripters community. However, it is still a shame that "make new project" clause will not accept a "template" property.
Imagine this line
tell application XCode
-- beware guys --- this does NOT work. make new project does not support templates
make new project with location: "~/Documents" name: "MyNewPlug" using template "MyCompanyPlugTemplate"
end tell
Here is the script that DOES work, which is rather lengthy, and ugly.
property plugName : "NewPlug"
property companyName : "YourCompany"
tell application "System Events" -- responsible for UI scripting
try
tell process "Xcode"
set frontmost to true
if (window "New Project" exists) then
select window "New Project"
else -- open the "New Project" dialog
keystroke "N" using {command down, shift down}
repeat until (window "New Project" exists)
end repeat
end if
-- select a template
tell window "New Project"
tell group 1
tell splitter group 1
-- Find our company's section of templates by name (may move when 3rd party templates are installed)
repeat with r in rows of outline 1 of scroll area 1
if ((value of UI element 1 of r) as string) is companyName then select r
end repeat
-- imitate the user configuring the template using the TemplateChooser panel.
tell splitter group 1
click button "Plug-in" of radio group 1 of scroll area 1 -- Select the "Plug-in" category of project templates.
click (every checkbox of scroll area 2 whose value is 1) -- reset all checkboxes to get the standard plug-in.
end tell
end tell
end tell
-- Complete by choosing the template, typing in the new project name, and creating the new plug.
click button "Choose…" of group 2
repeat until (sheet 1 exists)
end repeat
keystroke plugName
-- pause and wait for user to dismiss the sheet, allowing him to change the directory and default name.
repeat until ((sheet 1 exists) is false)
delay 0.5
end repeat
delay 3
end tell -- "New Project" dialog window
-- if user hit "save" and created the project, the "New Project" dialog has closed too. Otherwise ("Cancel") it is still there.
if ((window "New Project" exists) is false) then
-- go on, and continue configuring the new project!!!!
set sourcePlug to choose file of type {"xcodeproj"} with prompt "Select existing project to extract sources from"
end if
end tell -- XCode
on error errMessage
display dialog errMessage
end try
end tell -- System events
On 24/11/2009, at 17:45, Matt Neuburg wrote:
> On or about 11/23/09 11:53 PM, thus spake "Motti Shneor" <email@hidden>:
>
>> How can I tell XCode to create a new project using a predefined template?
>>
>> I could not find anything on that in the dictionary
>
> http://lists.apple.com/archives/xcode-users//2008/Feb/msg00497.html
>
> m.
>
> --
> matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
> pantes anthropoi tou eidenai oregontai phusei
> Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
> AppleScript: the Definitive Guide, 2nd edition
> http://www.tidbits.com/matt/default.html#applescriptthings
> Take Control of Exploring & Customizing Snow Leopard
> http://tinyurl.com/kufyy8
> RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
> TidBITS, Mac news and reviews since 1990, http://www.tidbits.com
>
>
>
Motti Shneor
Senior Software Engineer
Waves Audio ltd.
[mailto: email@hidden]
--- ceterum censeo Microsoftinem delendam esse ---
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden