screenshots-iphone.sh (2126B)
1 #!/bin/bash 2 set -euo pipefail 3 4 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" 5 REPO_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" 6 source "${SCRIPT_DIR}/select-simulator.sh" 7 8 ADD_DYNAMIC_ISLAND=true 9 while getopts "n" opt; do 10 case $opt in 11 n) ADD_DYNAMIC_ISLAND=false ;; 12 *) ;; 13 esac 14 done 15 shift $((OPTIND - 1)) 16 17 MAJOR="${1:-26}" 18 select_simulator "$MAJOR" 19 20 echo "Using ${DEVICE}, iOS ${RUNTIME}" 21 22 UDID=$(xcrun simctl list devices available "iOS ${RUNTIME}" \ 23 | grep "$DEVICE" \ 24 | head -1 \ 25 | sed 's/.*(\([A-F0-9-]*\)).*/\1/') 26 27 xcrun simctl boot "$UDID" 2>/dev/null || true 28 xcrun simctl bootstatus "$UDID" -b 29 30 xcrun simctl status_bar "$UDID" override \ 31 --time "9:41" \ 32 --batteryState discharging \ 33 --batteryLevel 100 \ 34 --wifiBars 3 \ 35 --cellularBars 4 \ 36 --cellularMode active \ 37 --dataNetwork wifi 38 39 echo "Status bar overridden" 40 41 DERIVED_DATA="/tmp/crossmate-screenshots-derived" 42 SCREENSHOT_TMP="/tmp/crossmate-screenshot.png" 43 OUTPUT_PATH="${REPO_DIR}/iphone_0.png" 44 BUNDLE_ID="net.inqk.crossmate" 45 46 rm -rf "$DERIVED_DATA" "$SCREENSHOT_TMP" 47 48 xcodebuild build \ 49 -scheme "Crossmate" \ 50 -project "${REPO_DIR}/Crossmate.xcodeproj" \ 51 -destination "platform=iOS Simulator,name=${DEVICE},OS=${RUNTIME}" \ 52 -derivedDataPath "$DERIVED_DATA" \ 53 2>&1 54 55 APP_PATH="${DERIVED_DATA}/Build/Products/Debug-iphonesimulator/Crossmate.app" 56 if [ ! -d "$APP_PATH" ]; then 57 echo "Built app not found at ${APP_PATH}" >&2 58 exit 1 59 fi 60 61 xcrun simctl install "$UDID" "$APP_PATH" 62 xcrun simctl launch --terminate-running-process "$UDID" "$BUNDLE_ID" \ 63 --crossmate-marketing-screenshot 64 65 sleep 3 66 67 xcrun simctl io "$UDID" screenshot --mask ignored "$SCREENSHOT_TMP" 68 xcrun simctl status_bar "$UDID" clear 2>/dev/null || true 69 70 if [ ! -f "$SCREENSHOT_TMP" ]; then 71 echo "Screenshot capture failed." >&2 72 exit 1 73 fi 74 75 echo "" 76 if [ "$ADD_DYNAMIC_ISLAND" = true ]; then 77 echo "Adding Dynamic Island..." 78 swift "${SCRIPT_DIR}/screenshots-iphone-island.swift" "$SCREENSHOT_TMP" "$OUTPUT_PATH" 79 else 80 echo "Skipping Dynamic Island..." 81 cp "$SCREENSHOT_TMP" "$OUTPUT_PATH" 82 fi 83 84 echo "" 85 echo "Screenshot saved to ${OUTPUT_PATH}" 86 ls -la "$OUTPUT_PATH"