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: Tue, 24 Nov 2009 06:39:27 -0500
- Acceptlanguage: en-US
- Thread-topic: XCode Scripts Menu item examples
On 23/11/2009, at 19:51, Matt Neuburg wrote:
> On Sun, 22 Nov 2009 09:34:12 -0500, Motti Shneor <email@hidden> said:
>> Hello.
>>
>> Does anyone know where I can find example AppleScripts for XCode, such that I can use within the XCode scripts menu?
>>
>> Apple provides only 3 such scripts (Delete Line, Move Line Up and Move Line Down) that all implement one simple thing - manipulating text on the frontmost open text window.
>>
>> However, I want to know what is available to the script when run, in terms of XCode objects --- how can I know from within the script
>> (there's no "Tell application "XCode" line there...
>>
>> how many projects are open? (set myCount to (count projects)) results in an error, ---- some class cannot be cast to another cast...
>>
>> Any hints? Documentation links? User forums? Downloads? Help please.
>
> You seem to be asking specifically about AppleScript. So... If your script
> is running in the Xcode Scripts menu, you don't *need* a tell block, because
> Xcode is the default target (and the terms block, which you can see in the
> examples, makes certain that the terminology is resolved); nothing stops you
> from using one, though. Alternatively, you can run your script form
> elsewhere.
>
Thanks. But if The application is the default or pre-set target for AppleScript commands, what is the effect of the Input settings for the scripts on the script menu? (None, Selection, Entire Document) ? How can my script access this input? I thought this pre sets the target of my script, only I could not figure out to WHAT.
By the way, the errors went away on the same very script I tried, so maybe it was just a mixed-up XCode that needed a re-launch. This can also explain the weird results (and even a crash) I got when trying a simple "display dialog" from my script. Anyhow, it works now. Thanks.
> As for your specific example, this works fine on my machine:
>
> tell application "Xcode" to count projects
>
> It sounds as if the real problem is that you don't know AppleScript? But in
> that case, the AppleScript-Users list might be a better place to ask
> questions; of course, my solution would be, learn the language (i.e. read my
> book, perhaps) and then just study the dictionary and experiment like crazy,
> the usual heuristic.
>
I'm quite experienced with AppleScript (over 10 years of scripting most everything scriptable on the Mac) although I did not yet read your book, I promise to do so soon.
The XCode dictionary, like most dictionaries, is quite obscure and misses lot's of stuff in XCode (that might be, alas, non-scriptable stuff...). Experimenting like crazy takes lots of time, and Scripting Samples are usually the fastest way to go when you have a focused goal.
Here is my bigger plan, so maybe you can see what I need ----
I am building a tool that creates new XCode projects using
1. A complicated cutstom template
2. An old, existing project, from which I should extract the sources and resources, and copy/merge them into the new project.
I already struggled a lot with the Template system (undocumented on its own right) and managed to create something reasonable. I could not find any way to introduce any coding/scripting/pre/post processing into the template system, to do my second stage, though.
So.... I thought the script-menu could provide what I need, writing an AppleScript that will
1. Choose and create the new project from the right template
2. Continue to manipulate the new project as described above.
I tripped over item 1. Can't make XCode create a project using a template! Extrapolating on the time I spent struggling with XCode Templates, I decided to turn here before wasting lots of time again.
Here's my next actual question:
How can I tell XCode to create a new project using a predefined template?
I could not find anything on that in the dictionary. The only properties you can provide "make new project" are a location and a name. This is mostly unusable to anyone, as empty projects aren't that useful, and configuring a project from scratch can be a lengthy and tricky task.
I tried also going the "GUI Scripting" way, but for some reason menu-scripting did not work for me too. I've done lots of experimenting too.
Also, I found the "Menu Suite" inside XCode dictionary, but could never find a way to actually make a menu-item work. First, menus and menu items are not accessible by name (which is weird), and the "choose menu item" command simply does NOTHING for me.
What's wrong with
tell application "Xcode"
activate
tell menu 2 of main menu
choose menu item 1
end tell
end tell
It compiles, runs, and does nothing... And yes, I enabled assistive devices on the Universal Access preferences panel.
Again --- any hint, or link to some XCode scripting sample, will be very helpful.
Motti Shneor
------------------------------------------
Senior Software Engineer
Waves Audio ltd.
[mailto: email@hidden]
_______________________________________________
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