#!/usr/bin/env bash # Xcode-style "Build and Run" (⌘R): build the app and launch it in place from # DerivedData, replacing any running instance. set -euo pipefail PROJECT="Museion.xcodeproj" SCHEME="Museion" CONFIGURATION="${1:-Debug}" APP_NAME="Museion.app" cd "$(dirname "$0")/.." # script lives in scripts/; repo root is the parent echo "Building $CONFIGURATION..." log=$(mktemp -t museion-run) trap 'rm -f "$log"' EXIT if ! xcodebuild -project "$PROJECT" -scheme "$SCHEME" \ -configuration "$CONFIGURATION" -destination 'platform=macOS' \ -quiet build >"$log" 2>&1; then echo "Build failed:" >&2 cat "$log" >&2 exit 1 fi PRODUCTS_DIR=$(xcodebuild -project "$PROJECT" -scheme "$SCHEME" \ -configuration "$CONFIGURATION" -showBuildSettings 2>/dev/null \ | awk -F'= ' '/BUILT_PRODUCTS_DIR = / {print $2; exit}') APP="$PRODUCTS_DIR/$APP_NAME" if [[ ! -d "$APP" ]]; then echo "Build did not produce $APP" >&2 exit 1 fi # Kill only the instance running from this exact DerivedData bundle; # never match by name alone — an installed Museion.app shares it. pkill -f "$APP/Contents/MacOS/" 2>/dev/null || true # Wait briefly for it to exit, else `open` may just re-activate the dying process. for _ in {1..20}; do pgrep -f "$APP/Contents/MacOS/" >/dev/null || break; sleep 0.1; done echo "Launching: $APP" open "$APP"