Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- set -euo pipefail
- # ====== Configuration ======
- WINDOW="SP Football Life 2027"
- PROCESS="FL 2027 start.exe"
- TIMEOUT_APPEAR=90 # only for the initial window appearance
- # ===========================
- # Flatpak → host helper
- if [[ -f /.flatpak-info ]]; then
- HOST_CMD=(flatpak-spawn --host)
- else
- HOST_CMD=()
- fi
- # Prefer kdotool, fall back to xdotool
- if "${HOST_CMD[@]}" command -v kdotool >/dev/null 2>&1; then
- TOOL_CMD=("${HOST_CMD[@]}" kdotool)
- elif "${HOST_CMD[@]}" command -v xdotool >/dev/null 2>&1; then
- TOOL_CMD=("${HOST_CMD[@]}" xdotool)
- else
- echo "Error: neither kdotool nor xdotool found" >&2
- exit 1
- fi
- window_exists() {
- [[ -n "$("${TOOL_CMD[@]}" search --name "$WINDOW" 2>/dev/null || true)" ]]
- }
- # Wait for the window to appear (with timeout so the script doesn't hang forever if the game fails to start)
- start=$SECONDS
- while ! window_exists; do
- if (( SECONDS - start >= TIMEOUT_APPEAR )); then
- echo "Timeout: window '$WINDOW' did not appear within ${TIMEOUT_APPEAR}s" >&2
- exit 1
- fi
- sleep 0.15
- done
- # Wait until the window disappears — no timeout, play as long as you want
- while window_exists; do
- sleep 0.5
- done
- # Game has closed → clean up the process if it's still lingering
- "${HOST_CMD[@]}" pkill -f "$PROCESS" 2>/dev/null || true
Advertisement
Add Comment
Please, Sign In to add comment