3

I have never used AppleScript before, but I am trying to write a script that will open Xcode and run the correct app on the correct simulator. Unfortunately I keep stumbling into syntax errors and I am somewhat baffled by the documentation (for a language designed to be like English, it's giving me more trouble than it's worth). I figured out how to open Xcode with the "Activate" command, but am stuck on how to click a specific button. From what I understand I should be able to say something like click button 1 of group 1 of window 1 or something like that, but not only is that giving me syntax errors (as are the many variants I've tried), but also I don't know how to figure out which window is window 1, which group is group 1, etc. I tried using the Accessibility Inspector but couldn't make heads or tails out of it. Can anyone point me in the right direction?

EDIT This is not a repeat of the linked question. That question was about running a build command. I want to actually click buttons in Xcode, and am trying to run the "run" command with the simulator.

3
  • 2
    try stackoverflow.com/questions/1007082/… Commented Jun 25, 2013 at 2:10
  • somehow I hadn't found that. Looks like this might be a repost. I'll try that and see how it goes. Thanks! Commented Jun 25, 2013 at 2:12
  • So I took a look at that piece of code. It seems to build my project successfully, but what I really want to do is choose a scheme and simulator and click the run button, which would be a different script with which I am still struggling. Commented Jun 25, 2013 at 2:25

1 Answer 1

9

A quick and easy way is to simulate the keystroke:

tell application "Xcode"
    activate
    tell application "System Events"
        perform (keystroke "r" using command down)
    end tell
end tell
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, but what if I want to specify the scheme and simulator first? Are there keystrokes for that?
I tried putting a compound tell process "Xcode" statement inside your tell application "System Events" statement with the line click (pop up button whose description is "Active Scheme"), but I got the error: Can’t get pop up button whose description = "Active Scheme".
(I chose description is "Active Scheme" because the button that brings up the pop up menu I want says it has AXDescription "Active Scheme." Is that right?)
@Kvass you should be able to do this using Xcode's scripting terminology but it's a bit of a pain and my applescripting skills are not good… you can use Automator Record/Watch Me Do the steps if you want to script the UI. feel free to wait for a more complete answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.