screenshots-iphone.sh (3311B)
1 #!/bin/bash 2 set -euo pipefail 3 4 DO_COMPOSE=false 5 while getopts "c" opt; do 6 case $opt in 7 c) DO_COMPOSE=true ;; 8 *) ;; 9 esac 10 done 11 shift $((OPTIND - 1)) 12 13 MAJOR="${1:-26}" 14 RUNTIME=$(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 20 if [ -z "$RUNTIME" ]; then 21 echo "No available iOS ${MAJOR}.x simulator runtime found." >&2 22 exit 1 23 fi 24 25 DEVICE=$(xcrun simctl list devices available "iOS ${RUNTIME}" \ 26 | grep "iPhone" \ 27 | head -1 \ 28 | sed 's/^ *\(.*\) ([A-F0-9-]*).*/\1/') 29 30 if [ -z "$DEVICE" ]; then 31 echo "No available iPhone simulator found for iOS ${RUNTIME}." >&2 32 exit 1 33 fi 34 35 echo "Using ${DEVICE}, iOS ${RUNTIME}" 36 37 # Boot simulator if needed 38 UDID=$(xcrun simctl list devices available "iOS ${RUNTIME}" \ 39 | grep "$DEVICE" \ 40 | head -1 \ 41 | sed 's/.*(\([A-F0-9-]*\)).*/\1/') 42 43 xcrun simctl boot "$UDID" 2>/dev/null || true 44 45 # Override status bar: 9:41, full signal, full battery 46 xcrun 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 55 echo "Status bar overridden" 56 57 SCREENSHOT_TMP="/tmp/listless-screenshots" 58 FRAMED_TMP="/tmp/listless-framed" 59 MARKETING_DIR="$(pwd)/Marketing" 60 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" 61 62 # Screenshot captions for composing 63 CAPTIONS=( 64 "Syncs via iCloud" 65 "Minimalist" 66 "Gesture Based" 67 "(Slightly) Customisable" 68 ) 69 70 # Run screenshot tests (writes to SCREENSHOT_TMP) 71 xcodebuild 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 # Clear status bar override (ignore errors if simulator already shut down) 78 xcrun simctl status_bar "$UDID" clear 2>/dev/null || true 79 80 if ! ls "${SCREENSHOT_TMP}"/*.png 1>/dev/null 2>&1; then 81 echo "No screenshots found in ${SCREENSHOT_TMP}." 82 exit 1 83 fi 84 85 mkdir -p "${MARKETING_DIR}" 86 87 if [ "$DO_COMPOSE" = true ]; then 88 # Frame with Framous, then compose onto background with text 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}" 110 else 111 # Raw screenshots with Dynamic Island overlay 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 121 fi 122 123 rm -rf "${SCREENSHOT_TMP}" 124 125 if [ "$DO_COMPOSE" = true ]; then 126 echo "" 127 echo "Screenshots saved to ${MARKETING_DIR}/" 128 ls -la "${MARKETING_DIR}"/iphone_*.png 129 else 130 echo "" 131 echo "Screenshots saved to ${OUTPUT_DIR}/" 132 ls -la "${OUTPUT_DIR}"/iphone_*.png 133 fi