I can build using the Xcode command line tools, is there any way I can actually run the application using them? (E.g. the equivalent to pressing Cmd+R in Xcode)
11 Answers
First decide what device you want to use:
xcrun simctl list
This will give you a list of devices:
-- iOS 9.0 --
iPhone 4s (56632E02-650E-4C24-AAF4-5557FB1B8EB2) (Shutdown)
iPhone 5 (ACD4DB7B-9FC9-49D5-B06B-BA5D5E2F5165) (Shutdown)
iPhone 5s (A8358B76-AD67-4571-9EB7-FFF4D0AC029E) (Shutdown)
iPhone 6 (1D46E980-C127-4814-A1E2-5BE47F6A15ED) (Shutdown)
iPhone 6 Plus (FD9F726E-453A-4A4C-9460-A6C332AB140B) (Shutdown)
Choose the ID (eg. FD9F726E-453A-4A4C-9460-A6C332AB140B) you want (you can create your own device using xcrun simctl create
if you want).
Boot the simulator with that device (replacing YOUR-DEVICE-ID with the ID)
/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator -CurrentDeviceUDID <YOUR-DEVICE-ID>
Now you should be able to use simctl to install and launch commands.
xcrun simctl install <YOUR-DEVICE-ID> <PATH-TO-APPLICATION-BUNDLE>
xcrun simctl launch <YOUR-DEVICE-ID> <BUNDLE-ID-OF-APP-BUNDLE>
xcrun simctl help
for more details. Note that booting a device using simctl does not currently (Xcode 7.2) allow you to do anything else with that device such as launch or install applications. You need to launch the device in the simulator to actually do anything interesting. Also, you cannot delete a device that is in use by the simulator, so you will have to quit/kill the simulator before attempting to delete anything.
-
9A little tip.. once the device is booted, you can use the keyword
booted
instead of<YOUR-DEVICE-ID>
. Nov 8, 2016 at 15:54 -
1You can find compiled application bundle in:
/Users/username/Library/Developer/Xcode/DerivedData/YourApp-cuozdynseabctdefrjsejhldxden/Build/Products/Debug-iphonesimulator
Oct 17, 2018 at 8:22 -
@kosiara-BartoszKosarzycki Is there a command line to show that path ?– code-8Mar 26, 2019 at 18:15
-
24
open -a Simulator --args -CurrentDeviceUDID <YOUR-DEVICE-ID>
also works for starting the simulator– sgdesmetAug 2, 2019 at 7:15 -
1
This worked for me:
open -a simulator
-
@Benjith Kizhisseri , this answer was already posted here: stackoverflow.com/a/49992522/6898523 please avoid duplicate answers. Dec 5, 2018 at 13:16
-
@MAhipalSingh, I didn't see any
not appropriate
word in comment and As a reviewer there's predefine options where you only able to select from them.– KuldeepDec 5, 2018 at 13:21 -
4I can't see why this "does not provide an answer to the question". This is the shortest answer to the question in this page and therefore this is a useful answer.– yshahakDec 24, 2018 at 5:55
-
It doesn't answer the question because it doesn't run the application. The poster wanted something that would run an app for them, not just launch the simulator.– dmaclachMar 28, 2019 at 4:05
-
1
This is the answer you are looking for:
Open terminal
xcrun simctl list
Get udid of the device you want to launch
Paste this in the terminal
open -a Simulator --args -CurrentDeviceUDID 0566AC33-9B91-2DR2-B5BB-C916D3BA8MD3
Open your terminal and paste this code:
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
Use xcrun simctl list
to get a list of simulators and their UDIDs.
Then open a specific simulator using xcrun simctl boot <UDIDs>
-
3It should be noted that this does boot the simulator, but does not actually open the UI. For that, you still need
open -a Simulator
. Nov 6, 2021 at 5:50 -
My list displays the error xcrun simctl list 2021-12-06 18:20:20.358 xcodebuild[12224:520286] [MT] DVTAssertions: ASSERTION FAILURE in /Library/Caches/com.apple.xbs/Sources/IDEXcode3ProjectSupport/IDEXcode3ProjectSupport-18132/Xcode3Core/LegacyProjects/Frameworks/DevToolsCore/DevToolsCore/Foundation/Specifications/XCSpecification.m:1504 Details: propertyList should be an instance inheriting from TSPropertyListDictionary, but it is nil Object: <XCSpecificationProxy: 0x7fca68666110> Method: -loadedSpecification Thread: <NSThread: 0x7fca667098d0>{number = 1, name = main} Hints:– sejnDec 6, 2021 at 12:51
open /Applications/Xcode.app/Contents/Developer/Applications/iOS\ Simulator.app/
-
That will just launch the Simulator, I'm looking for a way to do the same as Cmd+R in the terminal, launching the Simulator AND running the app Jul 2, 2015 at 8:57
-
The app must be installed trough Xcode to the simulator. Once you have done that at least once, you app will be saved on the simulator and accesible either from Xcode or Terminal. You can not compile by any means your code without Xcode @AlexChesters Jul 2, 2015 at 9:00
-
-
Sure you can compile your code trough terminal. But you are still using
Xcode Command Line Tools
. Examplexcodebuild test -scheme MyiOSApp -destination 'platform=iOS,name=iPod touch'
@AlexChesters Jul 2, 2015 at 9:16
One of the best solution :
- Launch iOS simulator from Terminal by providing name of the device
xcrun simctl boot $(xcrun simctl list devices | grep -m 1 'iPhone 12 Pro' |grep -E -o -i '([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})')
- This cmd will seamlessly launch the ios simulator for 'iPhone 12 Pro' device
summing-up
open -a Simulator && xcrun simctl boot 'iPhone 8 Plus'
-
This worked perfectly for updating an Alfred workflow. Will expand into a tiny shell script as a standalone answer. Nov 12 at 0:48
Here is a handy command to build the project and then run it in the terminal:
xcodebuild -scheme <scheme_name> -destination <destination_name> build && xcrun simctl launch booted <bundle_identifier>
<scheme_name>
- the name of the specific schema, e.g. "MyApp (Dev Environment)"
<destination_name>
- the name of the simulator on which to run. For example "name=iPhone 14 Pro"
<bundle_identifier>
- bundle of your project. Example: com.johnne.myapp
Execution result:
- The project will be built first;
- If the build was successful, your project will run on the selected simulator.
The final command with the data above will look like this:
xcodebuild -scheme "MyApp (Dev Environment)" -destination "name=iPhone 14 Pro" build && xcrun simctl launch booted com.johnne.myapp
As promised, wrote a tiny shell script to launch the XCode Simulator from the command line. Takes the advice from this thread and builds a user prompt around xcrun simctl list
and xcrun simctl boot
.
Quickstart
λ run-ios-sim
Enter phone model (e.g., iPhone 13 mini):
iphone 13
Choose a device type:
1 iPhone 13 Pro
2 iPhone 13 Pro Max
3 iPhone 13 mini
4 iPhone 13
Pass argument directly
λ run-ios-sim iphone 13 mini
Choose a device type:
1 iPhone 13 mini
1
iPhone 13 mini already booted
General usage
λ run-ios-sim -h
Run iOS simulator from the command line.
USAGE
./run-ios-sim [device_type] (e.g., "iPhone 13 mini")
OPTIONS
-h --help Show this help message.
-l --list List available device types.
-i Install script to ~/.local/bin (then call as `run-ios-sim`).
Happy to turn into a proper repo if there's enough interest 🤞
open /Applications/Xcode.app/Contents/Applications/iOS\ Simulator.app
?