20

How can one run a project on multiple destinations (say, iPhone, iPad and iSimulator) at once? Xcode Product optionsXcode multiple destinations


There are 2 related questions:

  1. Xcode 4 - One Click Build to Multiple Devices?
  2. Run on simulator and phone with one click

The 1ˢᵗ question (supposedly) has an answer, but I can't figure out how exactly should you use the Aggregate target (if this is the right direction at all), and apparently neither could Josh Kahane, the OP; the "answer" still somehow got/remained accepted.

The 2ⁿᵈ question was closed down as a "duplicate", as if the 1ˢᵗ one provided a (workable) answer.


Added a bounty: (how) can one use Aggregate target for simultaneous, multiple Build & Run? Perhaps one can achieve simultaneous, multiple Build & Run via some .sh script using xcodebuild? Any other possible solution?

3
  • 2
    2019 and Apple still doesn't provide a built in method to do this. Commented Jun 14, 2019 at 15:13
  • 2021 and Apple still doesn't provide a built in method to do this. Commented Oct 20, 2021 at 13:13
  • 2022 and Apple still doesn't provide a built in method to do this. Commented Jan 8, 2022 at 18:36

5 Answers 5

15

UPDATE: Apple removed support for this type of plugin as of Xcode 8. AppleScript is probably your best bet.

I ran into the same issue, so I wrote an Xcode plugin to help out with this. I found it to be more robust and easier to invoke than the AppleScript options.

The plugin is called KPRunEverywhereXcodePlugin and is available via Alcatraz or on GitHub: https://github.com/kitschpatrol/KPRunEverywhereXcodePlugin

New menu items

Hope this helps!

Sign up to request clarification or add additional context in comments.

11 Comments

Hmmm, thanks for the script, installs fine, but when I choose Run Everywhere, it just builds, but doesn't run on any of my plugged in devices?
@Smikey, I just tested the plugin again on Xcode 6 and it seems fine. If you're still having this problem, could you please open an issue with more info on GitHub? github.com/kitschpatrol/KPRunEverywhereXcodePlugin
One click install and everything works fine! Would be perfect if you could also include one of the simulators to run with.
Did I ever tell you that you are awesome? I don't think I have. You are awesome. Thank you.
How do you deal with an error like this on startup?: [MT] PluginLoading: Required plug-in compatibility UUID E969541F-E6F9-4D25-8158-72DC3545A6C6 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/KPRunEverywhereXcodePlugin.xcplugin' not present in DVTPlugInCompatibilityUUIDs
|
13

It's actually simpler than I thought. This AppleScript puts some pain out of Xcode:

tell application "Xcode" activate end tell tell application "System Events" tell application process "Xcode" click menu item "1st iDevice Name" of menu 1 of menu item "Destination" of menu 1 of menu bar item "Product" of menu bar 1 click menu item "Run" of menu 1 of menu bar item "Product" of menu bar 1 delay 5 click menu item "2nd iDevice Name" of menu 1 of menu item "Destination" of menu 1 of menu bar item "Product" of menu bar 1 click menu item "Run" of menu 1 of menu bar item "Product" of menu bar 1 delay 5 click menu item "iPhone 6.1 Simulator" of menu 1 of menu item "Destination" of menu 1 of menu bar item "Product" of menu bar 1 click menu item "Run" of menu 1 of menu bar item "Product" of menu bar 1 end tell end tell 
  1. Save the above AppleScript as an .app. (Customize delays to your machine.)
  2. Create a new Service in Automator: choose Launch Application and select the .app from previous step.
  3. Save Service from previous step and give it a keyboard shortcut. Tip: avoid shortcuts with ^, since it will bring up this dialog: enter image description here

Granted, this isn't strictly a simultaneous 'Build & Run', but it sure beats manually trifling between destinations.

5 Comments

does this still work? I tried doing this and OSX tells me it no longer support classic mode "because the classic environment is no longer supported"
@joon, works fine on latest Mavericks. Not sure about Yosemite though. (Although this is besides the point, since I presume the Classic refers to OS 9.)
@courteous This is great, I'm triggering it from automator directly (which is just fine) since on El Capitan I got the following error "You can’t open the application because PowerPC applications are no longer supported." and the service does not appear on the services menu of the Xcode app... still very helpful!
Works fine on Mojave
I've just used Automator to run an iOS and Mac app "simultaneously" on my machine after being sick of manually selecting and running on each device. What a day to be alive ✌🏻
6

Here is a script that will build and run on all connected iOS devices. To use:

  1. Open "Automator".
  2. Create a new "Quick Action".
  3. Select "no input" for "Workflow receives".
  4. Select Xcode for the application.
  5. Add a "Run JavaScript" action and paste the script.
  6. Save as "Run on All", you can now access this from the Xcode -> Services menu from Xcode.

Javscript:

function run(input, parameters) { var xcode = Application("Xcode"); var ws = xcode.activeWorkspaceDocument(); var genericDest = null; var devices = []; ws.runDestinations().forEach(function(runDest) { if (runDest.platform() != "iphoneos") return; if (runDest.device().generic()) { genericDest = runDest; } else { devices.push(runDest); } }); devices.forEach(function(device) { ws.activeRunDestination = device; var buildResult = ws.run(); while (true) { if (buildResult.completed()) break; if (buildResult.buildLog() && buildResult.buildLog().endsWith("Build succeeded\n")) break; delay(1); } delay(1); }); } 

5 Comments

Hi , this is not working for me. I select the service in xcode and nothing happens. How can i test this and check what is the problem?
Works well for me. One thing to note is that in Mojave it appears that the Automator steps are named slightly different. For step 2 instead of "Service" choose "Quick Action" and for step 3 "Workflow receives"
Can anyone please point me to the documentation of this? what other API do we have other than platform() ?
To see the methods available open Script Editor, go File > Open Dictionary and choose Xcode. Change language from AppleScript to JavaScript.
This is very nice. Thanks.
1

It would indeed be nice to have multiple uploads at once with Xcode. However as I understand it, aggregate only allows you to compile multiple targets, not run them.

Given the second part of you question (after the edit) I can point you to another way to do it. You won't have xcode attached (but gdb in console mode) and you should be able to make it simultaneous on several device, although this was not the primary goal. This particular solution doesn't work with simulator, but there are other methods for those.

launching iOS App from Mac OS X console

2 Comments

How would you do it for LLDB? Including the simulator would be awesome as well. @aggregate target, yes that is my understanding as well. I can't fathom why the 1ˢᵗ related question has an accepted answer.
Since GDB is simply launched from the terminal, using lldb would be a matter of finding out the correct command.
0

Here's a script that will run all of the devices currently available in your Product -> Destination menu. NB: it relies on the following conditions:

  1. Devices are selected from the Product -> Destination menu (could change in future versions of Xcode)
  2. The menu item before your devices is named "My Mac 64-bit" (could change in future versions of Xcode)
  3. The menu item after your devices is named "iOS Simulator" (guess when that might change?)

    tell application "Xcode" activate end tell tell application "System Events" tell process "Xcode" set deviceMenu to menu 1 of menu item "Destination" of menu 1 of menu bar item "Product" of menu bar 1 set allUIElements to entire contents of deviceMenu set startAfterName to "My Mac 64–bit" set stopName to "iOS Simulator" set started to false repeat with anElement in allUIElements try set menuName to name of anElement if menuName is equal to stopName then set started to false exit repeat else if menuName is equal to startAfterName then set started to true else if started then click menu item menuName of menu 1 of menu item "Destination" of menu 1 of menu bar item "Product" of menu bar 1 click menu item "Run" of menu 1 of menu bar item "Product" of menu bar 1 delay 5 end if end try end repeat end tell end tell 

1 Comment

Oldie, but goodie has been superseded by github.com/kitschpatrol/KPRunEverywhereXcodePlugin .

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.