iOS Simulator Terminal Commands `$ xcrun simctl`
source link: https://gist.github.com/patriknyblad/be3678bf6b515f11b602051530b5ac3e
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Managing iOS Simulators
List all simulators created
$ xcrun simctl list --json
Delete old and unavailable simulators
$ xcrun simctl delete unavailable
Open Simulator.app
$ open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/
Boot specific simulators
You can find the id/name by listing all simulators $ xcrun simctl list
.
$ xcrun simctl boot AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEE // UUID Hex string
$ xcrun simctl boot "iPhone XS Max" // Name of simulator
Create a simulator with a specific name
You can name simulators and use them for specific purposes.
$ xcrun simctl create iPhone7-my-app com.apple.CoreSimulator.SimDeviceType.iPhone-8 com.apple.CoreSimulator.SimRuntime.iOS-10–3
Shutdown Simulator
$ xcrun simctl shutdown booted
$ xcrun simctl shutdown AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEE
$ xcrun simctl shutdown "iPhone7-my-app"
$ xcrun simctl shutdown "iPhone XS"
$ xcrun simctl shutdown all
Erase contents in Simulator
Similar to running a factory restore on your device
$ xcrun simctl erase AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEE
$ xcrun simctl erase "iPhone7-my-app"
$ xcrun simctl erase "iPhone XS"
$ xcrun simctl erase all
Add media to simulator
$ xcrun simctl addmedia booted ./video_01.mp4
$ xcrun simctl addmedia "iPhone XS" ./video_01.mp4
Working with apps
Install App
$ xcrun simctl install booted "./path/to/ios-app.app"
$ xcrun simctl install "iPhone XS Max" "./path/to/ios-app.app"
Uninstall App
$ xcrun simctl uninstall booted com.mycompany.myapp
$ xcrun simctl uninstall "iPhone XS Max" com.mycompany.myapp
Launch app
$ xcrun simctl launch booted com.mycompany.myapp
$ xcrun simctl launch "iPhone XS Max" com.mycompany.myapp
Terminate app
$ xcrun simctl terminate booted com.mycompany.myapp
$ xcrun simctl terminate "iPhone XS Max" com.mycompany.myapp
Open URL
Can also be used to open an app, if you open the app using a url the first time it will give you an alert asking if you want to navigate to that app.
$ xcrun simctl openurl booted https://google.com
$ xcrun simctl openurl "iPhone XS Max" https://google.com
$ xcrun simctl openurl booted myapp://
$ xcrun simctl openurl "iPhone XS Max" myapp://
Record simulator video
$ xcrun simctl io booted recordVideo — type=mp4 ./simulator-record_001.mp4
$ xcrun simctl io "iPhone XS Max" recordVideo — type=mp4 ./simulator-record_001.mp4
Screenshot simulator
$ xcrun simctl io booted screenshot ./simulator-screenshot_001.png
$ xcrun simctl io "iPhone XS Max" screenshot ./simulator-screenshot_001.png
More help provided using help command
$ xcrun simctl help
Example scripts
Run an app on many simulators
I created and use this script for running the app I am developing in all possible screen sizes at once to verify that everything looks and works as intended.
#!/bin/bash
# List of simulators: `$ xcrun simctl list`
SIMULATORS=("iPhone SE" "iPhone 8" "iPhone 8 Plus" "iPhone XS" "iPhone XS Max" "iPhone XR")
# Comment or remove variables to skip a step
APP_PATH="/path/to/my/build/directory/when/running/a/build/in/xcode/app.app"
APP_IDENTIFIER="com.mycompany.myapp" # Identifier from info.plist
OPEN_URL="myapp://some/page/in/app" # Deep linking
echo "Running on ${#SIMULATORS[*]} simulators."
for index in ${!SIMULATORS[*]}
do
SIMULATOR=${SIMULATORS[$index]}
echo "Booting ${SIMULATOR}..."
xcrun simctl boot "${SIMULATOR}"
if [ ! -z "$APP_PATH" ]
then
echo "${SIMULATOR} installing: ${APP_PATH##*/}"
xcrun simctl install "${SIMULATOR}" "${APP_PATH}"
fi
if [ ! -z "$APP_IDENTIFIER" ]
then
echo "${SIMULATOR} opening app: ${APP_IDENTIFIER}"
xcrun simctl launch "${SIMULATOR}" "${APP_IDENTIFIER}"
fi
if [ ! -z "$OPEN_URL" ]
then
echo "${SIMULATOR} opening url: ${OPEN_URL}"
xcrun simctl openurl "${SIMULATOR}" "${OPEN_URL}"
fi
done
References:
Recommend
-
80
README.md lazygit A simple terminal UI for git commands, written in Go with the gocui library.
-
49
A while ago, we wrote about ExplainShell , a web-based tool to learn what each part of a Linux command does. It divides the...
-
46
Display CLI Commands Explanation In Terminal
-
8
xcode-select, xcrun & Friends macOS Developer Directory macOS has the notion of a system-wide active developer directory for Xcode and BSD tools. It contains necessary programs to be a...
-
11
Categories common xcrun: error: active developer path (“/Applications/Xcode.app/Contents/Developer”) does not exist ...
-
7
“xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun” – git in terminal does not work after macOS upgrade to Catalina
-
6
5 March 2021 / mac #Mac git命令报错 xcrun: error: invalid active developer path 某天,升级完MacOS到Big Sur 11.2.2,然后突然发现git不好用了...
-
8
In this tutorial, we’ll look at how to install and use Lazygit on Linux and macOS. Lazygit is a simple terminal UI for git commands, written in Go with the gocui library. Lazygit enables you t...
-
5
Mac OS: xcrun: error: invalid active developer path, missing xcrun ...
-
4
Workaround: Xcode simctl status_bar is still broken for iOS 17 simulators 04 January 2024 ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK