listless

A simple list app for Apple platforms
Log | Files | Refs | README | LICENSE

screenshots-ipad.sh (3400B)


      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 # Prefer iPad Pro 13" for ASC screenshots (2064x2752)
     26 DEVICE=$(xcrun simctl list devices available "iOS ${RUNTIME}" \
     27   | grep "iPad Pro 13" \
     28   | head -1 \
     29   | sed 's/^ *\(.*\) ([A-F0-9-]*).*/\1/')
     30 if [ -z "$DEVICE" ]; then
     31   DEVICE=$(xcrun simctl list devices available "iOS ${RUNTIME}" \
     32     | grep "iPad" \
     33     | head -1 \
     34     | sed 's/^ *\(.*\) ([A-F0-9-]*).*/\1/')
     35 fi
     36 
     37 if [ -z "$DEVICE" ]; then
     38   echo "No available iPad simulator found for iOS ${RUNTIME}." >&2
     39   exit 1
     40 fi
     41 
     42 echo "Using ${DEVICE}, iOS ${RUNTIME}"
     43 
     44 # Boot simulator if needed
     45 UDID=$(xcrun simctl list devices available "iOS ${RUNTIME}" \
     46   | grep "$DEVICE" \
     47   | head -1 \
     48   | sed 's/.*(\([A-F0-9-]*\)).*/\1/')
     49 
     50 xcrun simctl boot "$UDID" 2>/dev/null || true
     51 
     52 # Override status bar: 9:41, full signal, full battery
     53 xcrun simctl status_bar "$UDID" override \
     54   --time "9:41" \
     55   --batteryState discharging \
     56   --batteryLevel 100 \
     57   --wifiBars 3 \
     58   --cellularBars 4 \
     59   --cellularMode active \
     60   --dataNetwork wifi
     61 
     62 echo "Status bar overridden"
     63 
     64 SCREENSHOT_TMP="/tmp/listless-screenshots"
     65 FRAMED_TMP="/tmp/listless-framed"
     66 MARKETING_DIR="$(pwd)/Marketing"
     67 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
     68 
     69 # iPad Pro 13" ASC canvas dimensions
     70 CANVAS_WIDTH=2064
     71 CANVAS_HEIGHT=2752
     72 
     73 CAPTIONS=(
     74   "Syncs via iCloud"
     75   "Minimalist"
     76   "Gesture Based"
     77   "(Slightly) Customisable"
     78 )
     79 
     80 # Run screenshot tests (same iOS UI test target, different simulator)
     81 xcodebuild test \
     82   -scheme "Listless iOS" \
     83   -destination "platform=iOS Simulator,name=${DEVICE},OS=${RUNTIME}" \
     84   -only-testing:"Listless iOS UI Tests/ListlessiOSScreenshots" \
     85   2>&1
     86 
     87 # Clear status bar override (ignore errors if simulator already shut down)
     88 xcrun simctl status_bar "$UDID" clear 2>/dev/null || true
     89 
     90 if ! ls "${SCREENSHOT_TMP}"/*.png 1>/dev/null 2>&1; then
     91   echo "No screenshots found in ${SCREENSHOT_TMP}."
     92   exit 1
     93 fi
     94 
     95 mkdir -p "${MARKETING_DIR}"
     96 
     97 if [ "$DO_COMPOSE" = true ]; then
     98   mkdir -p "${FRAMED_TMP}"
     99 
    100   echo ""
    101   echo "Framing screenshots..."
    102   n=0
    103   for file in "${SCREENSHOT_TMP}"/0*.png; do
    104     shortcuts run "Frame Screenshots" -i "$file" -o "${FRAMED_TMP}/framed_${n}.png"
    105     echo "  Framed screenshot ${n}"
    106     n=$((n + 1))
    107   done
    108 
    109   echo "Composing final images..."
    110   n=0
    111   for file in "${FRAMED_TMP}"/framed_*.png; do
    112     caption="${CAPTIONS[$n]:-}"
    113     swift "${SCRIPT_DIR}/screenshots-ios-compose.swift" "$file" "${MARKETING_DIR}/ipad_${n}.png" "$caption" "$CANVAS_WIDTH" "$CANVAS_HEIGHT"
    114     echo "  ipad_${n}.png — ${caption}"
    115     n=$((n + 1))
    116   done
    117 
    118   rm -rf "${FRAMED_TMP}"
    119 else
    120   OUTPUT_DIR="$(pwd)"
    121   echo ""
    122   n=0
    123   for file in "${SCREENSHOT_TMP}"/0*.png; do
    124     cp "$file" "${OUTPUT_DIR}/ipad_${n}.png"
    125     n=$((n + 1))
    126   done
    127 fi
    128 
    129 rm -rf "${SCREENSHOT_TMP}"
    130 
    131 if [ "$DO_COMPOSE" = true ]; then
    132   echo ""
    133   echo "Screenshots saved to ${MARKETING_DIR}/"
    134   ls -la "${MARKETING_DIR}"/ipad_*.png
    135 else
    136   echo ""
    137   echo "Screenshots saved to ${OUTPUT_DIR}/"
    138   ls -la "${OUTPUT_DIR}"/ipad_*.png
    139 fi