Python Screenshot Script

I have created an automated Python Script that takes a screenshot every 10 seconds and saves it to your desired folder. I have used the script for some Pentests where it becomes tedious to take a screenshot for every step.

import pyautogui
import time
import os

# Define the folder where screenshots will be saved
output_folder = "D:\\Screenshots_Folder"

# Create the folder if it doesn't exist
if not os.path.exists(output_folder):
    os.makedirs(output_folder)

# Initialize a counter for the screenshots
screenshot_counter = 1

# Function to take a screenshot and save it
def take_screenshot(counter):
    # Define the filename using the counter
    screenshot_name = f"Screenshot_{counter}.png"
    
    # Define the full path for the screenshot
    screenshot_path = os.path.join(output_folder, screenshot_name)
    
    # Take a screenshot and save it
    screenshot = pyautogui.screenshot()
    screenshot.save(screenshot_path)
    
    print(f"Screenshot saved at {screenshot_path}")

# Main loop to take a screenshot every 10 seconds
try:
    while True:
        take_screenshot(screenshot_counter)
        screenshot_counter += 1  # Increment the counter for the next screenshot
        time.sleep(10)  # Wait for 10 seconds before taking the next screenshot
except KeyboardInterrupt:
    print("Screenshot capture stopped.")

If you have any questions for comments regarding my script, feel free to reach out to me. I will be happy to listen to any comments or suggestions.