Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch specific iOS simulator?

Tags:

xcode

ios

Is there a simple way to launch a iOS simulator through the command line. I am working in a project, and it's got some complicated to get the UUID of a simulator using grep, and then launch it by its UUID:

UUID=$(
  xcrun instruments -s |
  grep "${{ matrix.device }}" |   # Grep device(s) - can expect more than one
  grep -Eo -m1 "\[.*\]" |         # Extract device ID of the first result
  sed -e 's/^\[//' -e 's/\]$//'   # Trimming the square brackets surrounding UUID
)
xcrun simctl boot "$UUID"
like image 729
Ben Butterworth Avatar asked Jul 20 '26 09:07

Ben Butterworth


1 Answers

Get a list of device names:

Run xcrun simctl list devices, which would output:

== Devices ==
-- iOS 14.5 --
-- iOS 14.5 --
    iPhone 8 (FA86F02A-B7AF-412B-996C-7B086025A73C) (Shutdown)
    iPhone 8 Plus (F9FB94EA-3EFE-497E-A994-7C112CD65462) (Shutdown)
    iPhone 11 (C14D6993-CA37-4E50-86C9-0D2827B35D48) (Shutdown)
    iPhone 11 Pro (4E137620-962B-4756-B913-2EE9AF99D3D6) (Shutdown)
    iPhone 11 Pro Max (935DA14A-A4AB-4EC0-8AFB-103ABF2C6608) (Shutdown)
    iPhone SE (2nd generation) (1C78EEFC-293D-4EBD-8F4C-9FACEB842631) (Shutdown)
    iPhone 12 mini (A4ED4EF6-8F84-452F-927D-40BA30D6CF62) (Booted)
    iPhone 12 (92F57737-CB75-4A99-84BB-E221F156B578) (Booted)
    iPhone 12 Pro (C62C81AB-18C7-4DAD-9023-AD4E1A64140F) (Shutdown)
    iPhone 12 Pro Max (BF1967DF-A0A7-4740-961F-DCBEB4CAFF60) (Shutdown)
    iPod touch (7th generation) (47DFA553-1955-49BA-A4D3-CE7C397282AC) (Shutdown)
    iPad Pro (9.7-inch) (0E84438C-2369-4D26-ABBE-BC0B71E76839) (Shutdown)
    iPad (8th generation) (C7ABF216-2256-4715-9FAB-F83EA595ECEB) (Shutdown)
    iPad Air (4th generation) (E7B4E2E7-88F6-4133-ACE5-7B8B19E96F43) (Shutdown)
    iPad Pro (11-inch) (3rd generation) (9793FE60-0749-49D8-8ACE-4B46C1B4901B) (Shutdown)
    iPad Pro (12.9-inch) (5th generation) (8755F8FE-EDCB-4603-B0D0-262A83DC723A) (Shutdown)
-- tvOS 14.5 --
    Apple TV (3FEF7ABC-4CED-4473-9B76-63C19707B28C) (Shutdown)
    Apple TV 4K (2nd generation) (200C414D-4699-4F3A-8E28-0DC6D598E557) (Shutdown)
    Apple TV 4K (at 1080p) (2nd generation) (7363F807-A22F-49B2-917A-F248002EABDB) (Shutdown)
-- watchOS 7.4 --
    Apple Watch Series 5 - 40mm (71BD5079-1D90-421F-925C-4D9F288F7535) (Shutdown)
    Apple Watch Series 5 - 44mm (3F587446-DC30-4C5D-A101-0D6D53B3E71F) (Shutdown)
    Apple Watch Series 6 - 40mm (CAE878C0-9DD5-4E74-9BE9-2262819BA43D) (Shutdown)
    Apple Watch Series 6 - 44mm (000CCEE8-E41B-4D52-B755-69B37D2BBC5E) (Shutdown)
-- Unavailable: com.apple.CoreSimulator.SimRuntime.iOS-15-0 --
    iPad (9th generation) (B2819113-C651-47F8-9ABF-38FBB530927A) (Shutdown) (unavailable, runtime profile not found)
    iPad mini (6th generation) (B2D49664-1582-4A37-918B-53EA0ADAA898) (Shutdown) (unavailable, runtime profile not found)
    iPhone 13 (43F7E023-6AEF-4ED0-8FCC-E88303DE3B70) (Shutdown) (unavailable, runtime profile not found)
    iPhone 13 Pro (1C2C397B-9774-459A-B4F1-81CDE52D0246) (Shutdown) (unavailable, runtime profile not found)
    iPhone 13 Pro Max (0BCB5E9B-A527-46FA-B952-9F3629AF84D5) (Shutdown) (unavailable, runtime profile not found)
    iPhone 13 mini (00CBE649-0FD7-49EF-AE95-53DAAE3DDCBE) (Shutdown) (unavailable, runtime profile not found)
-- Unavailable: com.apple.CoreSimulator.SimRuntime.watchOS-8-0 --
    Apple Watch Series 7 - 41mm (DAC19B17-E885-4B21-B1B3-85969EE0E693) (Shutdown) (unavailable, runtime profile not found)
    Apple Watch Series 7 - 45mm (F73EAA78-5B3E-4E9D-8643-1EFC1CF1F990) (Shutdown) (unavailable, runtime profile not found)

Then, launch by device name:

xcrun simctl boot "iPhone 12"

Note: In CI/CD, you could use a device variable or matrix to run on multiple devices instead, e.g. xcrun simctl boot "${{ matrix.device }}".

To launch your app

Run xcrun simctl launch "iPhone 12" com.example.app-name. You can check the device is booted, by running xcrun simctl list devices | grep "iPhone 12".

To see the UI

Just open the Simulator.app

like image 51
Ben Butterworth Avatar answered Jul 23 '26 05:07

Ben Butterworth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!