3
votes

I'd like to use AppleScript to automate some of my common build tasks. But it appears under Xcode 4.2, scripting is so badly broken as to be useless. I cannot even run a minimal script such as the following (with Xcode running and my project loaded):

tell application "Xcode"
   build project of active project document
end tell

This gives me the error "missing value". The scripting dictionary supplied is opaque to say the least. Nothing I have found on the Developer site helps, and searching for answers elsewhere indicates I am not the only frustrated one. Does Apple not want us to use AppleScript with Xcode 4? I'm using 4.2 as I don't want to upgrade from Snow Leopard to Lion yet.

UPDATE: specific questions are 1) how do I perform simple AppleScripting with Xcode 4 and 2) where is this documented?

2
I spent 4 days trying to script 4.2 a few months ago; with no real results; however... this question may not meet the SO guidelines for not being a "rant disguised" unless you rephrase it around your specific scripting need. See the faq: stackoverflow.com/faq#dontask - Chris Trahey
What is the exact error? Does it only say "missing value"? Thanks :) - pasawaya
My specific scripting need at present is simply to get something - anything - running with Xcode 4. Once I have a toe in the door I will probably be able to take it from there. And yes, "missing value" is the sum total of the response. - David G

2 Answers

1
votes

Here is what I use to build & run on an attached iPhone. Even if an application does not support scripting, you can always just use menu commands. It's not what you want for a production environment but this is just supposed to be a little helper app of yours, right?

(* compile and let it run on iPhone *)
enabledGUIScripting(true)
activate application "Xcode"
tell application "System Events"
    tell process "Xcode"
        click menu item "Run" of menu 1 of menu bar item "Product" of menu bar 1
    end tell
end tell

on enabledGUIScripting(switch)
    tell application "System Events"
        activate -- brings System Events authentication dialog to front
        set UI elements enabled to switch
        return UI elements enabled
    end tell
end enabledGUIScripting
0
votes

To answer part 2, Xcode scripting is documented in its scripting dictionary. In AppleScript Editor, choose "Open Dictionary…" from the File menu and select Xcode.