Scripts/select-simulator.sh (1818B)
1
2
3
4
5
6
7
8
9
10select_simulator() {
11 local major="${1:-27}"
12
13 local runtime_lines
14 runtime_lines=$(xcrun simctl list runtimes available \
15 | grep "iOS ${major}\." \
16 | sort -t. -k1,1n -k2,2n -r || true)
17
18 if [ -z "$runtime_lines" ]; then
19 echo "No available iOS ${major}.x simulator runtime found." >&2
20 return 1
21 fi
22
23 local runtime_line="" device="" line version candidate
24 while IFS= read -r line; do
25 version=$(sed 's/.*iOS \([0-9.]*\).*/\1/' <<<"${line}")
26 candidate=$(xcrun simctl list devices available "iOS ${version}" \
27 | sed -n 's/^ *\(iPhone [0-9][0-9]* Pro\) ([A-F0-9-]*).*/\1/p' \
28 | sort -t' ' -k2,2n \
29 | tail -1 || true)
30 if [ -n "$candidate" ]; then
31 runtime_line="$line"
32 device="$candidate"
33 break
34 fi
35 done <<<"${runtime_lines}"
36
37 if [ -z "$device" ]; then
38 runtime_line=$(head -1 <<<"${runtime_lines}")
39 version=$(sed 's/.*iOS \([0-9.]*\).*/\1/' <<<"${runtime_line}")
40 device=$(xcrun simctl list devices available "iOS ${version}" \
41 | grep "iPhone" \
42 | head -1 \
43 | sed 's/^ *\(.*\) ([A-F0-9-]*).*/\1/' || true)
44 fi
45
46 RUNTIME=$(sed 's/.*iOS \([0-9.]*\).*/\1/' <<<"${runtime_line}")
47 DESTINATION_OS=$(sed 's/.*(\([0-9.]*\) -.*/\1/' <<<"${runtime_line}")
48 DEVICE="$device"
49
50 if [ -z "$DEVICE" ]; then
51 echo "No available iPhone simulator found for iOS ${RUNTIME}." >&2
52 return 1
53 fi
54}