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.

Kvass
  • 8,294
  • 12
  • 65
  • 108
  • 2
    try http://stackoverflow.com/questions/1007082/tell-applescript-to-build-xcode-project – jeremy Jun 25 '13 at 02:10
  • somehow I hadn't found that. Looks like this might be a repost. I'll try that and see how it goes. Thanks! – Kvass Jun 25 '13 at 02: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. – Kvass Jun 25 '13 at 02:25

1 Answers1

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
justin
  • 104,054
  • 14
  • 179
  • 226
  • Thanks, but what if I want to specify the scheme and simulator first? Are there keystrokes for that? – Kvass Jun 25 '13 at 13:07
  • 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".` – Kvass Jun 25 '13 at 14:06
  • (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 Jun 25 '13 at 14:14
  • @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. – justin Jun 26 '13 at 06:17