Scripts/select-simulator.sh (1035B)
1
2
3
4
5
6select_simulator() {
7 local major="${1:-27}"
8
9 local runtime_line
10 runtime_line=$(xcrun simctl list runtimes available \
11 | grep "iOS ${major}\." \
12 | sort -t. -k1,1n -k2,2n \
13 | tail -1 || true)
14
15 RUNTIME=$(sed 's/.*iOS \([0-9.]*\).*/\1/' <<<"${runtime_line}")
16 DESTINATION_OS=$(sed 's/.*(\([0-9.]*\) -.*/\1/' <<<"${runtime_line}")
17
18 if [ -z "$RUNTIME" ] || [ -z "$DESTINATION_OS" ]; then
19 echo "No available iOS ${major}.x simulator runtime found." >&2
20 return 1
21 fi
22
23 DEVICE=$(xcrun simctl list devices available "iOS ${RUNTIME}" \
24 | grep "iPhone" \
25 | head -1 \
26 | sed 's/^ *\(.*\) ([A-F0-9-]*).*/\1/' || true)
27
28 if [ -z "$DEVICE" ]; then
29 echo "No available iPhone simulator found for iOS ${RUNTIME}." >&2
30 return 1
31 fi
32}