I’m trying to create a custom generic Xcode behaviour, that once invoked will launch a script to generate AppleDoc documentation related to the current project opened in the ide.
I initially asked this question:
Xcode 4: custom behavior does not execute my sh script? which helped me to understand what I was missing: it’s not possible to use Xcode variables in external scripts!
So, my new question is: how can I use AppleScript to retrieve the informations I need (Project name, company, paths…)?
I’m pretty sure that this is possible, since Xcode is highly “scriptable”, but so far I was able to retrieve only the name of the xcode project file:
tell application "Xcode"
tell active project document
name
end tell
end tell
The code above returns “MyProject.xcodeproj”.
I’m a totally newbie when it comes to AppleScript and it’s hard for me to understand the reference in Xcode.sdef (the hierarchy seems pretty simple, but I’m unable to create the right script to retrieve what I want).
Can you give some hints or point me to a newbie-proof tutorial about AppleScript + Xcode?
(I didn’t find nothing but “hello world” for Finder examples :P)
The easiest thing to do is get properties of an item. So for example run this to get the properties of the frontmost project.
You will see the properties are a “record”. To access the items of a record you get them by their name. For example you can get the “real path” of the project…
Finally, when you look at the sdef file you do that using Applescript Editor application. Under the file menu chosse “open dictionary” and choose the application. Once the dictionary is open it’s useful to use the search field. For example search for “project” and then highlight the result corresponding to the “class”. This will show you what you can get from a project.
So you see we have a few ways to find out what information we can get from an application.