Scripts/screenshots-iphone.sh (3311B)
1
2set -euo pipefail
3
4DO_COMPOSE=false
5while getopts "c" opt; do
6 case $opt in
7 c) DO_COMPOSE=true ;;
8 *) ;;
9 esac
10done
11shift $((OPTIND - 1))
12
13MAJOR="${1:-26}"
14RUNTIME=$(xcrun simctl list runtimes available \
15 | grep "iOS ${MAJOR}\." \
16 | sed 's/.*iOS \([0-9.]*\).*/\1/' \
17 | sort -t. -k1,1n -k2,2n \
18 | tail -1)
19
20if [ -z "$RUNTIME" ]; then
21 echo "No available iOS ${MAJOR}.x simulator runtime found." >&2
22 exit 1
23fi
24
25DEVICE=$(xcrun simctl list devices available "iOS ${RUNTIME}" \
26 | grep "iPhone" \
27 | head -1 \
28 | sed 's/^ *\(.*\) ([A-F0-9-]*).*/\1/')
29
30if [ -z "$DEVICE" ]; then
31 echo "No available iPhone simulator found for iOS ${RUNTIME}." >&2
32 exit 1
33fi
34
35echo "Using ${DEVICE}, iOS ${RUNTIME}"
36
37
38UDID=$(xcrun simctl list devices available "iOS ${RUNTIME}" \
39 | grep "$DEVICE" \
40 | head -1 \
41 | sed 's/.*(\([A-F0-9-]*\)).*/\1/')
42
43xcrun simctl boot "$UDID" 2>/dev/null || true
44
45
46xcrun simctl status_bar "$UDID" override \
47 --time "9:41" \
48 --batteryState discharging \
49 --batteryLevel 100 \
50 --wifiBars 3 \
51 --cellularBars 4 \
52 --cellularMode active \
53 --dataNetwork wifi
54
55echo "Status bar overridden"
56
57SCREENSHOT_TMP="/tmp/listless-screenshots"
58FRAMED_TMP="/tmp/listless-framed"
59MARKETING_DIR="$(pwd)/Marketing"
60SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
61
62
63CAPTIONS=(
64 "Syncs via iCloud"
65 "Minimalist"
66 "Gesture Based"
67 "(Slightly) Customisable"
68)
69
70
71xcodebuild test \
72 -scheme "Listless iOS" \
73 -destination "platform=iOS Simulator,name=${DEVICE},OS=${RUNTIME}" \
74 -only-testing:"Listless iOS UI Tests/ListlessiOSScreenshots" \
75 2>&1
76
77
78xcrun simctl status_bar "$UDID" clear 2>/dev/null || true
79
80if ! ls "${SCREENSHOT_TMP}"/*.png 1>/dev/null 2>&1; then
81 echo "No screenshots found in ${SCREENSHOT_TMP}."
82 exit 1
83fi
84
85mkdir -p "${MARKETING_DIR}"
86
87if [ "$DO_COMPOSE" = true ]; then
88
89 mkdir -p "${FRAMED_TMP}"
90
91 echo ""
92 echo "Framing screenshots..."
93 n=0
94 for file in "${SCREENSHOT_TMP}"/0*.png; do
95 shortcuts run "Frame Screenshots" -i "$file" -o "${FRAMED_TMP}/framed_${n}.png"
96 echo " Framed screenshot ${n}"
97 n=$((n + 1))
98 done
99
100 echo "Composing final images..."
101 n=0
102 for file in "${FRAMED_TMP}"/framed_*.png; do
103 caption="${CAPTIONS[$n]:-}"
104 swift "${SCRIPT_DIR}/screenshots-ios-compose.swift" "$file" "${MARKETING_DIR}/iphone_${n}.png" "$caption"
105 echo " iphone_${n}.png — ${caption}"
106 n=$((n + 1))
107 done
108
109 rm -rf "${FRAMED_TMP}"
110else
111
112 OUTPUT_DIR="$(pwd)"
113 echo ""
114 echo "Adding Dynamic Island..."
115 n=0
116 for file in "${SCREENSHOT_TMP}"/0*.png; do
117 swift "${SCRIPT_DIR}/screenshots-iphone-island.swift" "$file" "${OUTPUT_DIR}/iphone_${n}.png"
118 echo " iphone_${n}.png"
119 n=$((n + 1))
120 done
121fi
122
123rm -rf "${SCREENSHOT_TMP}"
124
125if [ "$DO_COMPOSE" = true ]; then
126 echo ""
127 echo "Screenshots saved to ${MARKETING_DIR}/"
128 ls -la "${MARKETING_DIR}"/iphone_*.png
129else
130 echo ""
131 echo "Screenshots saved to ${OUTPUT_DIR}/"
132 ls -la "${OUTPUT_DIR}"/iphone_*.png
133fi