How to 'Build & Run' on multiple destinations at once in Xcode?
Solution 1
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
Hope this helps!
Solution 2
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
- Save the above
AppleScript
as an.app
. (Customizedelay
s to your machine.) - Create a new
Service
inAutomator
: chooseLaunch Application
and select the.app
from previous step. - Save
Service
from previous step and give it a keyboard shortcut. Tip: avoid shortcuts with ^, since it will bring up this dialog:
Granted, this isn't strictly a simultaneous 'Build & Run', but it sure beats manually trifling between destinations.
Solution 3
Here is a script that will build and run on all connected iOS devices. To use:
- Open "Automator".
- Create a new "Quick Action".
- Select "no input" for "Workflow receives".
- Select Xcode for the application.
- Add a "Run JavaScript" action and paste the script.
- 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);
});
}
Solution 4
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.
Related videos on Youtube
Blaz
Software developer focused on backend development, primarily using Elixir & OTP. Contact me.
Updated on January 07, 2020Comments
-
Blaz over 4 years
How can one run a project on multiple destinations (say, iPhone, iPad and iSimulator) at once?
There are 2 related questions:
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, multipleBuild & Run
? Perhaps one can achieve simultaneous, multipleBuild & Run
via some.sh
script usingxcodebuild
? Any other possible solution?-
Dani about 5 years2019 and Apple still doesn't provide a built in method to do this.
-
Witek Bobrowski over 2 years2021 and Apple still doesn't provide a built in method to do this.
-
Dave Y over 2 years2022 and Apple still doesn't provide a built in method to do this.
-
-
Blaz about 11 yearsHow 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.
-
TheThibz about 11 yearsSince GDB is simply launched from the terminal, using lldb would be a matter of finding out the correct command.
-
Smikey almost 10 yearsHmmm, 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?
-
joon almost 10 yearsdoes 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"
-
Blaz almost 10 years@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.)
-
kitschpatrol over 9 years@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
-
kalperin over 9 yearsOldie, but goodie has been superseded by github.com/kitschpatrol/KPRunEverywhereXcodePlugin .
-
Alex Cio over 9 yearsOne click install and everything works fine! Would be perfect if you could also include one of the simulators to run with.
-
Alex Zavatone about 9 yearsDid I ever tell you that you are awesome? I don't think I have. You are awesome. Thank you.
-
Alex Zavatone about 9 yearsHow 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
-
kitschpatrol about 9 years@AlexZavatone, do you have the latest version of the plugin? Which version of Xcode are you using? Please open an issue on GitHub if this is still a problem. Thanks.
-
Paul Slocum almost 9 yearsWorks for me in XCode 6.4. Makes testing so much less cumbersome.
-
Paul Slocum over 8 yearsI was using this for a while, but unfortunately it keeps getting broken with crash bugs when XCode is updated (currently not working for me on XCode 7.1 or 7.2)
-
Omer over 8 years@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!
-
kitschpatrol over 8 years@PaulSlocum Should be fixed.
-
Paul Linsay about 8 yearsThanks, works great on 7.3! Any advice on how to locate the UUID for Xcode when the latest version comes out?
-
ilan over 6 yearsHi , 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?
-
Aidan Host over 5 yearsWorks 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"
-
SevenDays over 5 yearsWorks fine on Mojave
-
Christophe Blin almost 5 yearsNot working at all in XCode 10 (probably because apple has removed support for plugins in v8)
-
gutte over 2 yearsCan anyone please point me to the documentation of this? what other API do we have other than
platform()
?