Skip to content

Instantly share code, notes, and snippets.

@tranphuquy19
Created November 2, 2025 07:44
Show Gist options
  • Select an option

  • Save tranphuquy19/566b20e1440df1c77f0c84213cb07c73 to your computer and use it in GitHub Desktop.

Select an option

Save tranphuquy19/566b20e1440df1c77f0c84213cb07c73 to your computer and use it in GitHub Desktop.
VS Code Modal Auto-Reload Script
#!/bin/bash
MAX_ITERATIONS=100
WAIT_BETWEEN_CHECKS=2
WAIT_AFTER_CLICK=1
echo "========================================"
echo "Script Auto-Reload VS Code Modals"
echo "========================================"
echo "Max iterations: $MAX_ITERATIONS"
echo "Wait between checks: ${WAIT_BETWEEN_CHECKS}s"
echo ""
iteration=0
total_processed=0
while [ $iteration -lt $MAX_ITERATIONS ]; do
iteration=$((iteration + 1))
# Find modal
found_modal=false
while IFS= read -r win_id; do
if xprop -id $win_id _NET_WM_STATE 2>/dev/null | grep -q "MODAL"; then
found_modal=true
title=$(xdotool getwindowname $win_id 2>/dev/null)
echo "[Iter $iteration] Found modal: ID=$win_id, Title='$title'"
# Click Reload Window
xdotool windowactivate $win_id 2>/dev/null
sleep 0.3
xdotool key Tab Return
total_processed=$((total_processed + 1))
echo "[Iter $iteration] ✓ Clicked 'Reload Window' (#$total_processed)"
sleep $WAIT_AFTER_CLICK
fi
done < <(xdotool search --class "code" 2>/dev/null)
# If no modal found
if [ "$found_modal" = false ]; then
echo ""
echo "========================================"
echo "✓ Completed!"
echo " - Total modals processed: $total_processed"
echo " - Number of checks: $iteration"
echo "========================================"
exit 0
fi
# Wait before checking again
echo "[Iter $iteration] Waiting ${WAIT_BETWEEN_CHECKS}s before checking again..."
sleep $WAIT_BETWEEN_CHECKS
done
echo ""
echo "========================================"
echo "⚠ Reached limit of $MAX_ITERATIONS checks"
echo " - Total modals processed: $total_processed"
echo "========================================"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment