scripts/take-screenshots.sh
75 lines · 3405 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 Debug
4# build's -screenshot launch argument (DayByDay/Screenshots/ScreenshotScene.swift) on a demo
5# child. The 6.3" set is 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="home routine animals train trace counting calendar progress"
13scenes="${*:-$all}"
14size="${TEXT_SIZE:-}"
15out=AppStore/screenshots${size:+-$size}
16derived=.build/screenshots
17app="$derived/Build/Products/Debug-iphonesimulator/DayByDay.app"
18bundle=net.cleberg.DayByDay
19
20xcodebuild build -project DayByDay.xcodeproj -scheme DayByDay -configuration Debug \
21 -destination 'generic/platform=iOS Simulator' -derivedDataPath "$derived" -quiet
22
23udid() {
24 xcrun simctl list devices available | grep -F " $1 (" | head -1 | sed 's/.*(\([0-9A-F-]\{36\}\)).*/\1/'
25}
26
27flatten() {
28 # Drops the alpha channel, which App Store Connect rejects.
29 sips -s format jpeg -s formatOptions 100 "$1" --out "$1.jpg" >/dev/null
30 sips -s format png "$1.jpg" --out "$1" >/dev/null
31 rm "$1.jpg"
32}
33
34shoot() { # device name, output folder
35 device="$(udid "$1")"
36 [ -n "$device" ] || { echo "No simulator named $1." >&2; exit 1; }
37 xcrun simctl boot "$device" 2>/dev/null || true
38 xcrun simctl bootstatus "$device" -b >/dev/null
39 xcrun simctl ui "$device" appearance light
40 xcrun simctl ui "$device" content_size "${size:-large}"
41 xcrun simctl install "$device" "$app"
42 mkdir -p "$out/$2"
43 for scene in $scenes; do
44 n="$(printf '%s\n' "$all" | tr ' ' '\n' | grep -nx "$scene" | cut -d: -f1)"
45 [ -n "$n" ] || { echo "Unknown scene $scene; one of: $all" >&2; exit 1; }
46 xcrun simctl terminate "$device" "$bundle" 2>/dev/null || true
47 # Set per launch: changing content_size restarts the status bar and drops the override.
48 xcrun simctl status_bar "$device" override --time 9:41 --dataNetwork wifi --wifiMode active \
49 --wifiBars 3 --cellularMode active --cellularBars 4 --batteryState charged --batteryLevel 100
50 xcrun simctl launch "$device" "$bundle" -screenshot "$scene" >/dev/null
51 file="$out/$2/$(printf %02d "$n")-$scene.png"
52 # A screen that has not drawn yet is blank white, which compresses to a few KB.
53 tries=0
54 while :; do
55 sleep 3
56 xcrun simctl io "$device" screenshot "$file" >/dev/null 2>&1
57 [ "$(stat -f%z "$file")" -gt 100000 ] && break
58 tries=$((tries + 1))
59 [ "$tries" -lt 10 ] || { echo "$scene stayed blank on $1." >&2; exit 1; }
60 done
61 flatten "$file"
62 echo "$file"
63 done
64 xcrun simctl terminate "$device" "$bundle" 2>/dev/null || true
65 xcrun simctl status_bar "$device" clear
66 xcrun simctl ui "$device" content_size large
67}
68
69shoot "iPhone 18 Pro Max" iphone-6.9
70shoot "iPad Pro 13-inch (M5)" ipad
71
72mkdir -p "$out/iphone-6.3"
73for file in "$out"/iphone-6.9/*.png; do
74 sips -z 2622 1206 "$file" --out "$out/iphone-6.3/$(basename "$file")" >/dev/null
75done