A few pieces of AppleScript automating project’s destination selection in Xcode. AFAIK, unfortunately there is no other way of controlling Xcode from outside, so we have to depend on the actual menu items of the interface.
If you run this the first time, you’re likely encounter this message: "AppleScript Editor.app" would like to control this computer using accessibility features. So you’ll need to grant access in System Preferences.
onset_destination(destination)tellapplication"System Events"tellprocess"Xcode"clickmenuitemdestinationofmenu1ofmenuitem"Destination"ofmenu1ofmenubaritem"Product"ofmenubar1click((firstpopupbuttonoflist1ofgroup2oftoolbar1offrontwindow)whosedescriptionis"Active Run Destination")endtellendtellendset_destinationset_destination("iOS Device")
Here you pass an actual destination string from the above as the parameter, eg. "iOS Device". The first line in the innermost code block actually selects the destination, while the second one (optional) allows you to open the destinations popup so that you can easily change it right away. To do that properly, activate Xcode first:
123
tellapplication"Xcode"activateendtell
Some extras
Two extra functions I found useful:
12345678910
-- Looks for any value from `values_array` in `array` and returns the first match. Otherwise, null.onfind_first_value_in_array(array,values_array)repeatwithvalueinvalues_arrayifarraycontainsvaluethenreturnvalueendifendrepeatreturnnullendfind_first_value_in_array
12345678
tojoinList(aList,delimiter)setretValto""setprevDelimitertoAppleScript's text item delimiterssetAppleScript's text item delimiterstodelimitersetretValtoaListas stringsetAppleScript's text item delimiterstoprevDelimiterreturnretValendjoinList
And the last tip for today: if you need to call a function in the global namespace from a tell application … end tell block, prepend the call with the word my.