#!/usr/bin/env bash
# Example: Find window containing text "error" in title

echo "Searching for window with 'error' in title..."

# Method 1: Use helper script
if SCREENSHOT=$(./scripts/capture-by-title.sh "error" 2>/dev/null); then
    echo "Found and captured: $SCREENSHOT"
else
    echo "No window found with 'error' in title"
fi

# Method 2: Direct niri commands
echo -e "\nAll windows:"
niri msg --json windows | jq -r '.[] | "[\(.id)] \(.title) (WS:\(.workspace_id))"'

echo -e "\nCapturing focused window..."
FOCUSED_ID=$(niri msg --json focused-window | jq -r '.id')
niri msg action screenshot-window --id "$FOCUSED_ID" --write-to-disk true
sleep 0.1
echo "Saved to: $(ls -t ~/Pictures/Screenshots/*.png | head -1)"
