scripts/take-screenshots.sh
76 lines · 3381 bytes · executable
1#!/bin/sh
2# Takes the App Store screenshots on the iPhone 18 Pro Max (6.9") and iPad Pro 13-inch (M5)
3# simulators, in light mode at 9:41 with a full status bar. Each screen opens through the
4# -UITesting -screenshot launch arguments (App/Sources/ScreenshotScene.swift). The 6.3" set is
5# resized from the 6.9" one; every PNG is flattened to RGB.
6# Usage: scripts/take-screenshots.sh [scene ...] (default: every scene, in App Store order)
7# TEXT_SIZE=accessibility-extra-extra-extra-large (any simctl content_size) shoots at that text
8# size into AppStore/screenshots-<size> instead.
9set -eu
10
11cd "$(dirname "$0")/.."
12all="fold flap cup models"
13scenes="${*:-$all}"
14size="${TEXT_SIZE:-}"
15out=AppStore/screenshots${size:+-$size}
16derived=.build/screenshots
17app="$derived/Build/Products/Debug-iphonesimulator/Fold.app"
18bundle=sh.krz.fold
19
20xcodegen generate --spec App/project.yml --quiet
21xcodebuild build -project App/Fold.xcodeproj -scheme Fold -configuration Debug \
22 -destination 'generic/platform=iOS Simulator' -derivedDataPath "$derived" -quiet
23
24udid() {
25 xcrun simctl list devices available | grep -F " $1 (" | head -1 | sed 's/.*(\([0-9A-F-]\{36\}\)).*/\1/'
26}
27
28flatten() {
29 # Drops the alpha channel, which App Store Connect rejects.
30 sips -s format jpeg -s formatOptions 100 "$1" --out "$1.jpg" >/dev/null
31 sips -s format png "$1.jpg" --out "$1" >/dev/null
32 rm "$1.jpg"
33}
34
35shoot() { # device name, output folder
36 device="$(udid "$1")"
37 [ -n "$device" ] || { echo "No simulator named $1." >&2; exit 1; }
38 xcrun simctl boot "$device" 2>/dev/null || true
39 xcrun simctl bootstatus "$device" -b >/dev/null
40 xcrun simctl ui "$device" appearance light
41 xcrun simctl ui "$device" content_size "${size:-large}"
42 xcrun simctl install "$device" "$app"
43 mkdir -p "$out/$2"
44 for scene in $scenes; do
45 n="$(printf '%s\n' "$all" | tr ' ' '\n' | grep -nx "$scene" | cut -d: -f1)"
46 [ -n "$n" ] || { echo "Unknown scene $scene; one of: $all" >&2; exit 1; }
47 xcrun simctl terminate "$device" "$bundle" 2>/dev/null || true
48 # Set per launch: changing content_size restarts the status bar and drops the override.
49 xcrun simctl status_bar "$device" override --time 9:41 --dataNetwork wifi --wifiMode active \
50 --wifiBars 3 --cellularMode active --cellularBars 4 --batteryState charged --batteryLevel 100
51 xcrun simctl launch "$device" "$bundle" -UITesting -screenshot "$scene" >/dev/null
52 file="$out/$2/$(printf %02d "$n")-$scene.png"
53 # A screen that has not drawn yet is blank white, which compresses to a few KB.
54 tries=0
55 while :; do
56 sleep 3
57 xcrun simctl io "$device" screenshot "$file" >/dev/null 2>&1
58 [ "$(stat -f%z "$file")" -gt 30000 ] && break
59 tries=$((tries + 1))
60 [ "$tries" -lt 10 ] || { echo "$scene stayed blank on $1." >&2; exit 1; }
61 done
62 flatten "$file"
63 echo "$file"
64 done
65 xcrun simctl terminate "$device" "$bundle" 2>/dev/null || true
66 xcrun simctl status_bar "$device" clear
67 xcrun simctl ui "$device" content_size large
68}
69
70shoot "iPhone 18 Pro Max" iphone-6.9
71shoot "iPad Pro 13-inch (M5)" ipad
72
73mkdir -p "$out/iphone-6.3"
74for file in "$out"/iphone-6.9/*.png; do
75 sips -z 2622 1206 "$file" --out "$out/iphone-6.3/$(basename "$file")" >/dev/null
76done